To speed up the performance of your website, all CSS and JavaScript files should be minimized. That means, all CSS and JavaScript should delivered without unnecessary comments, spaces, line breaks and tabs. It should of course take place in the build process, otherwise your developers work is much harder! This tutorial shows how easily you can minimize files, by using the YUI Compressor.
Precondition
- Java is installed
- Latest version of YUI Compressor is downloaded
Minimize one file
# Syntax to minimize CSS
$ java -jar yuicompressor-x.y.z.jar style.css -o style-min.css
# Syntax to minimize JavaScript
$ java -jar yuicompressor-x.y.z.jar script.js -o script-min.js
Minimize multiple files
# Syntax to minimize CSS
$ java -jar yuicompressor-x.y.z.jar -o '.css$:-min.css' *.css
# Syntax to minimize JavaScript
$ java -jar yuicompressor-x.y.z.jar -o '.js$:-min.js' *.js
For more options show the help!
# show help
$ java -jar yuicompressor-x.y.z.jar --help