Compressing CSS and JS for live

Using Cloudflare to deliver your CSS and Javascripts is a great and easy way to ensure they're being served in the best way.

However, before pushing these assets to any webserver I also run them through various minification/compression tools to ensure they're as small as possible (and do things that Cloudflare simply can't do in realtime).

CSS Scripts

I use cssnano to take all my stylesheets, join them together and to compress them (by writing them/joining them together/removing redundant code).
I had tried other CSS minifiers out there, but some tried to be too clever and broke browsers' rendering.

To install it's

npm install cssnano postcss-cli -g

And to run it's

cat stylesheet.css | postcss --use cssnano --no-map > newstylesheet.css

Javascript

In a similar fashion to CSS I use UglifyJS 3 to compress my code

To install it's

npm install uglify-js -g

And to run it's

cat scripts.js | uglifyjs --compress --mangle --mangle-props > newscripts.js



Want to get in touch?