Speed Up Your Site – Auto File Compression
Posted by Jon Lee in Efficiency, Web Development, tags: compression, Efficiency, htaccess, JavaScript, speed-up-your-blog, web developmentIf speeding up Google Analytics doesn’t give you enough of a performance boost in terms of page load time, then maybe this will be of interest to you. Page load time is directly proportional to the size of files and objects being retrieved. By compressing files before they are sent across to the end user, you can cut load times down by almost 40% (varies).
Since the file compression is done server side, there will be an increase of server load but it is usually very minor and the gain in bandwidth is well worth it.
The Tools
The module required for file compression is mod_deflate. If your web server is running Apache 2.x then it should already be installed. I know the word deflate sounds counter-intuitive but trust me, it compresses your files. (Similarly, you could also use mod_gzip, both produce similar results but mod_gzip isn’t pre-installed with Apache).
Getting Started
First step is to turn the module on in your .htaccess file. Simply put this line to turn on the mod_deflate module:
SetOutputFilter DEFLATE
That’s pretty much all you have to do, but while you have the .htaccess file open, you can add a couple more lines to maximize the performance boost. First, is to set the compression level to maximum:
DeflateCompressionLevel 9
Next, some files do not need to be compressed since they are already compressed. This includes zip archives, images and executables. The following line will bypass these file types for compression:
SetEnvIfNoCase Request_URI \
\. ( ?:gif|jpeg|jpg|png|exe|tgz|gz|zip|gz2|rar) $ no-gzip dont-vary
Biggest Performance Boosts
You’ll see the biggest boost in text files like JavaScript, CSS and HTML files. File sizes will be reduced by about 50%. Depending on the number of images you have on your site this translates to anywhere between a 15 to 40% decrease in page load time.
Incompatibilities
In order for this to work, the end user must be running a browser that supports compressed files. Pretty much all browsers these days do so this isn’t a big deal but to the handful of people still currently running IE4 or Netscape 6, the page will not display properly.
Popularity: 3% [?]
Entries (RSS)