Comparison of JavaScript compression methods
November 30th, 2007While creating the build system for our Java web application, I set out to do some benchmarking on some of the different JavaScript compression methods. When our project builds, I configured our Ant build script to create three different version of our JavaScript files; full source, minified (comments and whitespace removed), and packed (compressed).
I also configured Tomcat to use gzip compression and then ran six different test, the three version of our JavaScript files without gzip compression and the three versions with gzip compression.
I measured the load time and size using FireBug from within Firefox and recorded the following results:
| Full Source | Minified | Packed | |
|---|---|---|---|
| Without GZIP | 167 KB | 329ms | 95 KB | 281ms | 70 KB | 313ms |
| With GZIP | 67 KB | 297ms | 48 KB | 219ms | 47 KB | 312ms |
Although my “tests” are very informal, I think that it is clear that the minified version with GZIP server compression offers the best results. It is only slightly larger than the packed version in size, but it loads almost 30% faster (due to the overhead of decompressing the packed version).
Tags: compression, gzip, javascript, tomcat












February 7th, 2008 at 4:20 am
Hi, how can i “GZIP” .js files using windows?
Is there any GUI mode?
Or like the Packer URL version? (http://dean.edwards.name/packer/)
Cheers!
Santiago.
Author Comment
Eric MartinFebruary 7th, 2008 at 8:44 am
@Santiago - gzip, as mentioned here, refers to the HTTP response compression by a web server and decompression by the web browser. So it’s not something you can physically do to a file. (UPDATE: Yes, you can physically compress a file using gzip, but this post is referring to server compression - thanks Peter)
Here is a great article that explains it all:
http://www.webreference.com/internet/software/servers/http/compression/
February 14th, 2008 at 5:31 am
OK. thanks!
February 14th, 2008 at 4:36 pm
Eric: gzip is the standard compression used on unix machines, it is indeed something a user can do to a file. WinZip and other Windows archiving platforms support compression and decompression.
Also see another take on the question.
Author Comment
Eric MartinFebruary 14th, 2008 at 5:13 pm
@Peter - I prefaced my response with “gzip, as mentioned here, refers to…”. I’ll change last sentence to be more clear, but again, I was speaking in terms of server compression not physical file compression.