Compress rate

Jan 15, 2012 at 6:00 PM

Could you please publish any samples and compress rates if it is possible

Coordinator
Jan 16, 2012 at 4:39 PM

Yes, that's a good idea. I'll try to compile a nice table of various compression tools and the results.

Coordinator
Jan 16, 2012 at 6:58 PM
Edited Feb 10, 2012 at 10:44 PM

I just ran a few tests on the latest release of jQuery, jQuery-1.7.1.js (248,235 bytes), using Microsoft Ajax Minifier (4.46), Google Closure Compiler (r1592), and YUI Compressor (2.4.7). Using the following command-lines:

Google Closure:      java -jar compiler.jar --js jquery-1.7.1.js --js_output_file jquery-1.7.1-closure.js
YUI Compressor:     java -jar yuicompressor-2.4.7.jar --type js jquery-1.7.1.js -o jquery-1.7.1-yui.js
AjaxMin:                 ajaxmin jquery-1.7.1.js -o jquery.1.7.1-ajaxmin.js

I received the following results:

TOOL                                               MINIFIED        MINIFIED+GZIP
YUI Compressor                                104,684          40,495
AjaxMin                                              93,690          37,916
Closure Compiler                                93,297          37,485

However, Closure Compiler by default does not preserve "important" comments, such as the licensing comments within the jQuery sources. Those comments add a few hundred bytes to the minification results for AjaxMin (and YUI Compressor). Although I believe it's important to preserve those comments in the output, if I want to compare the minification results of AjaxMin and Closure Compiler better, I can turn off important-comment support in AjaxMin (by adding the -comments:none switch) to get:

AjaxMin (no comments)                       93,148           37,567
Closure Compiler                                93,297           37,485

That's closer, and quite comparable. Of course, Closure Compiler also breaks lines around 500 characters by default, while AjaxMin puts everything on a single line. If I were to do the same with AjaxMin (adding the -line:500 switch), the gap would widen by a bit:

AjaxMin (no comments, broken lines)    93,327          37,873
Closure Compiler                                 93,297          37,485

But they're still pretty close.

One caveat: I'm not comparing with Closure Compiler's "Advanced Mode." In order to successfully leverage that mode of Closure Compiler, the developer must first code their sources in a particular manner to make sure the optimizations introduced by the tool don't break the semantics of the application. I haven't looked into it enough to see if Closure Compiler's Advanced Mode will break jQuery 1.7.1 or not; if it doesn't, then to be fair, Closure Compiler would probably be able to deliver even further compression. But again, that requires that the source code be written with Closure Compiler's Advanced Mode in mind from the beginning.

Hope that helps!

Jan 17, 2012 at 11:31 AM

Cool! Thanks