Optimisation

When CSS is heading for production, it takes an extra step through cssnano (http://cssnano.co/). It's a fantastic and modular CSS minifier by the extraordinarily talented Ben Briggs. Highly recommended.

Besides the more obvious minification step that cssnano provides, there are a number of micro-optimisations you can perform on your CSS just by incorporating plugins from the PostCSS eco-system. For example, by consistently ordering your CSS declarations, Gzip can compress the style sheet more effectively. That's not a job I want to do manually but the postcss-sorting (https://github.com/hudochenkov/postcss-sorting) plugin can do it for free. Here's comparison of Gzip file sizes using the various declaration sorting configurations.

To exemplify, I took a large test CSS file, and unsorted once Gzipped it was 37.59 kB. Here are the file sizes of that same file when Gzipped after using the other declaration sorting configurations:

  • postcss-sorting: 37.54
  • CSSComb: 37.46
  • Yandex: 37.48
  • Zen: 37.41

So at best we gain a saving of just under 1% of the original size. A tiny economy but one you can effectively get for free.

There are other such economies such as grouping alike media queries but I'll leave these micro-optimisations for you to explore should they pique your interest.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221