Compress JavaScript with Gzip
The main problem when we are using ajax framework is because of their big size. Of course, it will extremely slow down the sites load time. For example, if we use the standard jQuery, it’s almost 100Kb. It’s even more if we use the complete Prototype and Scriptaculous that will cost around 150Kb.
This is really nightmare for people who still use GPRS or the old 56kbps Dial-Up internet connection. It will takes minutes to load the sites or maybe it will takes forever because the browser usually won’t download it. Unfortunately, it’s very easy to solve this problem. Do you know that we can compress those files and reduce the size by half or more?
There are several method to compress javascript and I think one of the most efficient method is using Gzip Compression.

To implement the gzip compression for websites, first we need to gzip the Javascript files. For that purpose, we will need a gzip-compatible archiver / compressor. 7-zip is my favorite because it’s small, very fast and it’s completely free.
Gzip the JavaScript file, change the “gz” extension to “jgz” for safari compatibility and upload it to the same location together with the original script. Then next, we must ask apache to get the compressed version if there is available and finally tell the browser to un-compress the file before it can be used.
To do that, we add these following code in our .htaccess
RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.js$ $1\.js.jgz [L]
AddType “text/javascript” .js.jgz
AddEncoding gzip .jgz
That’s all. Yeah.. And if you want to look for another method this is it.:
- Joseph Scott’s Blog - Compressed JavaScript
- rakaz - Make your pages load faster by combining and compressing javascript and css files
- Added Bytes - PHP, Gzip and htaccess
- Let me have a blog - Using GZIP compression in web servers using .HTACCESS
- Apache Module - mod_deflate
- mod_gzip - Internet Content Acceleration module for the popular Apache Web Server






























