YUI JavaScript and CSS Compressor

I finally had some time/need to explore a new JavaScript compressor and had been hearing good things about the YUI compressor, so I took a look at it. The YUI compressor not only compresses (slightly better than JSMin) but claims to do some safe obfuscation. Altogether it claims to save an additional 18% over JSMin (5-10% over rhino), which is about what I experienced in my testing today. That is a substantial savings when your project uses over 200kb of JavaScript, such as Mint. I am pleased to say that I have now, not only met my 250kb library file goal, but surpassed it by another 30kb, by only switching my compression technology.

YUI compressor is a JAVA jar that requires JAVA 1.4. If you have JAVA in your classpath, you can use the following command:

java -jar pathToJar/yuicompressor-2.2.jar ––charset UTF-8 -o pathToOutput/filename pathToInput

If you use ant to build, then you might find the following helpful:

<java jar="pathToJar/yuicompressor-2.2.jar" fork="true" failonerror="true" output="pathToOutput/filename">
	<arg value="––charset" />
	<arg value="UTF-8" />
	<arg value="pathToInput/filename" />

One important thing to note is that if you don&rsquot;t include the "––charset <charset>" option, the compressor with print

"\n[INFO] Using charset UTF-8"

at the beginning of each file, which will break your JavaScript.

Additional Documentation