Category Archives: Apache

Compressed JavaScript on Apache HTTPD Server

As Java2Script’s library size is getting huger and huger, loading *.js is a critical job for Java2Script. And I decide to output compressed *.js to save loading bandwidth.

In httpd.conf or .htaccess file, add the following:

<IfModule mod_deflate.c>
# Netscape 4.x or IE 5.5/6.0
BrowserMatch ^Mozilla/4 no-gzip
# IE 5.5 and IE 6.0 have bugs! Ignore them until IE 7.0+
BrowserMatch \bMSIE\s7 !no-gzip
# Sometimes Opera pretends to be IE with "Mozila/4.0"
BrowserMatch \bOpera !no-gzip
AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript
Header append Vary User-Agent

You can read more about mod_deflate document.

In my experiments, I found that IE 6.0 had a strange bug in loading compressed *.js, so IE 6.0 was fed with huge raw *.js.

In normal bandwidth connection with Firefox 2.0, it takes about 16 seconds for the first time loading and running Java2Script application, and it takes about 6 seconds for later running (Cached *.js are applied). From the log file, there are about 20~30 *.js/*.css/*.png/*.gif hits, which counts up to about 150k. Thanks for the mod_deflate of Apache HTTPD Server. It saves a lot of bandwidth on those maybe 600k+ *.js files. And I considered such Java2Script application loading or running acceptable.

By the way, long waited Java2Script Milestone 5 release is coming. Lots of new features are added.

Update: For more details, please also read article “Compressing and Deploying JavaScript“.

Posted in Apache, JavaScript | Leave a comment