Using YUI Compressor to minify CSS

The YUI Compressor doesn't work only with JavaScript files, but also with style sheets. In this post I'm going to show you how to use this compressor to minify CSS files. Suppose that you have a large CSS file and you want to minify it. First, download YUI Compressor. Make sure that on your system is installed Java 1.4 or later. Decompress the package and put it on a directory. For the sake of this example, I'm assuming that the newly created directory is located under the root directory. Open your command prompt, change the working directory to the root and type:

java -jar yuicompressor-x.y.z.jar style.css

In this case I'm assuming that the CSS file is located in the same directory of the YUI Compressor, but you can specify a complete path if you want to. This is a basic usage of the YUI Compressor. The -x.y.z letters indicate the tool's version, so you have to substitute them when you run the previous example. A more advanced usage involves some parameters that allow you to specify how the output file should be treated. For example, here we use the -o parameter to redirect our input to an output file:

java -jar yuicompressor-x.y.z.jar style.css -o style.min.css

Again, you can use absolute paths to redirect everything elsewhere. There are many other parameters available that you can easily find here.

This entry was posted in , by Gabriele Romanato. Bookmark the permalink.

One thought on “Using YUI Compressor to minify CSS”

  1. That process is a scourge upon users who need to develop site-specific CSS, and users of web development tools attempting to evaluate a site's CSS, e.g.

Leave a Reply

Note: Only a member of this blog may post a comment.