A little more than a year and half ago I created a MSBuild Task for the YUI Compressor that was very well received, and even highlighted on the YUI Compressor site. At the time of writing that article YUI Compressor was king of the hill, and for the most part the only game in town that was really designed for production level use. Since then a number of new competitors have been released by Google and Microsoft, and I wanted to see how they stacked up against the YUI Compressor.
The setup of my machine is as follows:
- Windows 7 Pro (x64)
- Java 6 Update 17
- .NET 3.5 SP1
Each optimizer and the version:
I ran the following from the command line on jQuery 1.4 raw source code to produce the following files. Here is the raw source code file that I used in my testing:
ajaxmin jquery-1.4.js -o microsoft.js
ajaxmin -h jquery-1.4.js -o microsoft-h.js
Microsoft (Hypercrunch Combine Literals)
ajaxmin -hl jquery-1.4.js -o microsoft-hc.js
java -jar compiler.jar --compilation_level WHITESPACE_ONLY --js jquery-1.4.js
java -jar compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js jquery-1.4.js
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js jquery-1.4.js
java -jar yuicompressor-2.4.2.jar jquery-1.4.js -o yahoo.js
Yahoo (Minified Only)
java -jar yuicompressor-2.4.2.jar jquery-1.4.js --nomunge -o yahoo-m.js
Yahoo (Disabled Optimizations)
java -jar yuicompressor-2.4.2.jar jquery-1.4.js --disabled-optimizations -o yahoo-o.js
Yahoo (Preserve Unnecessary Semicolons)
java -jar yuicompressor-2.4.2.jar jquery-1.4.js --preserve-semi -o yahoo-s.js
The above testing produced the following results.
|Size (bytes)||Command Options||Size Optimization||Place|
|Microsoft (Hypercrunch Combine Literals)||67149||-hc||42.3902%||2|
|Google (Whitespace)||94225||--compilation_level WHITESPACE_ONLY||59.4829%||9|
|Google (Simple)||69467||--compilation_level SIMPLE_OPTIMIZATIONS||43.8535%||3|
|Google (Advanced)||63384||--compilation_level ADVANCED_OPTIMIZATIONS||40.0134%||1|
|Yahoo (Minify Only)||94843||--nomunge||59.8730%||10|
|Yahoo (Disabled Optimizations)||76465||--disable-optimizations||48.2712%||6|
|Yahoo (Preserve Unnecessary Semicolons)||77384||--preserve-semi||48.8514%||7|
The results are pretty clear of who won the top prizes in the above results. Out of the top 5 ranking outputs Google and Microsoft both took two of the positions and Yahoo took 1. Google Closure Compiler placed first when the Advanced Options were enabled which did really surprise me that much, and Microsoft AJAX Minifier placed second when Hypercrunch and Combine Literals were turned on. The Microsoft ranking, however was very surprising to me because of the lack-luster reviews of RC6 that was released back in October.
There are a couple things that should be noted about Google Closure with Advanced Options, which may not make the most beneficial option for you to choose when you are trying to minify your files.
- Removal of Code You Want to Keep
- Inconsistent Property Names
- Compiling Two Portions of Code Separately
- Broken References between Compiled and Uncompiled Code
Because of how the file is being optimized, it alters your code and would require you to do extra testing before deployment and it would make the resulting output almost impossible to debug against your un-minified version. So for these reasons it may not be the best choice, if you value ease of testing over byte size of your files.
So which ever option out of Microsoft, Google, or Yahoo you decide to use, all will produce a much more optimized-for-size file than the original. And, in my opinion, if you are already using Yahoo in your build environment there really isn’t much of a reason to switch, unless you are in the top tier of websites and need to squeeze every byte out of the file for delivery over the internet.
Personally, I am going to keep using YUI Compressor, because it has been rock solid in producing minimized and obfuscated code for my current projects, but in the future I may consider going with Microsoft or Google depending on what I am trying to accomplish.