October 10th, 2009

Speeding Up Your Website in 5 Minutes (Gzip Compression) by Selwin Ong

Page load times have become an increasingly discussed topics among web developers in the past few years, and for a good reason, it is directly tied to user experience – something we care deeply about.

There is a good reason why people still prefer reading printed magazines rather than just reading them online – pages in a magazine load instantly. Imagine if you need to wait for two seconds before the next page shows up every time you flip a page in a book – wouldn’t you be annoyed?

The two web giants today, Google and Yahoo both understood the importance of delivering content to end users as quickly as possible. Google Search is one of the most minimalist page on the web today (and it keeps getting smaller) and Yahoo is one of the pioneers of web performance research.

Many websites have discussed various ways in which you can implement best practices in speeding up websites but I find that most of them are lacking in thoroughness and are quite hard for a beginner sys admin to follow so I will try to make this as painless as possible.

One of the lowest hanging fruits in speeding up your website is to enable compression on text based files (HTML, CSS, JS). You can easily cut down the load time of these files by around 70%. Here’s how you would do it on Ubuntu 8.04 Hardy Heron (assuming you already have Apache 2 & PHP already set up correctly).

Step 1: enable mod_deflate and reload Apache (do this on your web server):

sudo a2enmod deflate && sudo /etc/init.d/apache2 reload

Step 2: tell Apache to compress text based files. Put these at the beginning of .htaccess in you DocumentRoot (create one if you don’t already have it). The default DocumentRoot in Ubuntu is located at “/var/www”:

#Deflate the files
IfModule mod_deflate.c

SetOutputFilter DEFLATE

Step 3: now check if your css and JS files are compressed. Visit this page and enter the URL of your website, CSS and JS files to see if they are indeed compressed.


Easy enough, right?

Copyright © 2020 User Inspired Technology Services.