- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
Five Javascript Compressors Compared
Without a doubt Ajax application are becomming more powerful. That also means that Javascript files are getting bigger and more complex. One solution is to use mod_gzip and mod_deflate (Apache) or HTTP compression (IIS). This means adding extra processing time both at the server and the client, however. One other way to cut down on bandwidth and memory is to compress the Javascript, after all, the browser doesn't need the nicely formated Javascript with white space and comments. You can just trim all of that out and save tons of space.
With that in mind, I decided to test out some of the better known Javascript compression algorithms. My test consisted of compressing three files: ClientEngine.js from the Echo2 framework, prototype.js from Prototype version 1.4.0, and a GWT ( Google Web Toolkit) compiled file from a small widget project. The GWT file was edited slightly to turn it from an HTML file into a Javascript file.
The compression tools tested were:
- Memtronic's Javascript/HTML Cruncher-Compressor v1.0k - Does a straighforward whitespace/comment crunching and a more fundamental transformation, aka compression.
- Dojo Shrinksafe - Rhino based. Supposed to be "safe."
- Creativyst Javascript Compressor - Pretty standard whitespace/comment stripper.
- Dean Edward's Packer - takes a little different tack, transforming and evaluation the Javascript as a string. Allows the compression of Javascript keywords, like 'function.'
- Douglas Crockford's JSMin - Also a pretty standard whitespace/comment stripper.
The results of my test are in the table below.
| File | Size | Memtronics Crunch |
Memtronics Compress |
Dojo Shrinksafe |
Creativyst | Packer | JSMin |
| Prototype | 47k | 28.91% | 69.52% | 30.96% | 18.52% | 59.40% | 23.42% |
| ClientEngine | 104k | 53.93% | 83.63% | 58.62% | 49.15% | 79.40% | 51.28% |
| GWT File | 42k | 8.11% | 52.43% | -1.00% | 0.00% | 23.30% | 5.96% |
The GWT file is already partially compressed, so a more fundamental transformation needs to happen in order to squeeze it some more. The Echo2 file was the largest and also was formatted for human consumption with comments, indentation, descriptive identifiers, etc., so it showed the greatest compression ratio.
Of the three "advanced" compressors, all of them had issues with prototype.js (syntax errors in the resulting code), but Dojo Shrinksafe didn't have any issues with the other two files. Packer seemed to work OK in IE6, but not in Firefox. Memtronic seemed to have problems in all three in both IE6 and Firefox.
The lesson? Test your compressed Javascript in all browser versions you plan to support (JsUnit, anyone?) or just use mod_deflate and company to handle your compression needs.
Topics: Javascript, Performance
Comments: 6 so far
Leave a comment
About Pathfinder
Recent
- Roles Testing For Security
- Blackbird takes the pain out of JavaScript logging
- Making GWT JSON not Quite so Painful
- IDEA - preconference workshop 06 Oct 08
- HTML5, Ajax history management, and The Ajax Experience 2008 Boston
- A Look Back At Past Posts
- Flash Player on iPhone gossip
- Microsoft to Jump on Board EC2
- TAE Boston 2008: The Unsexy Presentations
- The Ajax Experience 2008: Hope to see you in Beantown
Archives
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006


Here’s another compressor: http://verens.com/archives/2006/04/17/jsquash-a-javascipt-compressor/
I’d be interested to see how it compares.
Comment by Kae Verens, Friday, August 18, 2006 @ 3:06 am
just tried compressing prototype with my own compressor - it takes ten minutes just to replace “element” with “Z”. on the plus side, it doesn’t hang up your browser while it’s working.
Comment by Kae Verens, Friday, August 18, 2006 @ 3:25 am
I use Memtronic’s on a regular basis, and it works great for me… however, I also use http://www.jslint.com to make sure that there are no errors in the code to begin with. Because these compressors often put everything on one line, it makes JavaScript statements that do not end with a semi-colon invalid. I used prototype about a six months ago with an earlier version of Memtronic’s compressor - it took me a week to get it right, but I was able to compress it.
Comment by Jeremy Nicoll, Saturday, August 26, 2006 @ 10:26 am
There are serious errors in these compressors, many of them won’t let prorotype-1.4.0 pass without errors.
Comment by Michal Till, Thursday, October 19, 2006 @ 8:41 pm
This one let prototype-1.4.0 pass without errors and it beats all the above compressors in efficiency too: http://www.bananascript.com/
Comment by Michael, Saturday, January 6, 2007 @ 4:12 am
Ripper Not Allowed Here…!
Just Go To Hell…!
HaHaHa…!
Comment by danielscreamo, Friday, April 18, 2008 @ 9:45 am