Speed up your website using Gzip compression

Dec 27th, 2009 | By | Category: seo techniques


How to speed up your website using Gzip compression

As mentioned on another post regarding the Google caffeine update and the new websites load time ranking factor. its very important to try and optimise your websites loading speed.

There are a few ways of getting this done and will try and explain.

The first way is possible if your server supports mod_gzip or mod_deflate

On one of my sites I  use a hostgator shared server which doesnt support this. However their dedicated and VPS servers do.

if your server does support this then you can add some coding to your .htaccess file which will enable the compression for you. 

Our job here will be to configure the server so that it will return zip content should the users browser support this.

On Apache servers this can be done by adding the following code to the .htaccess file

# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE

If for some reason you can not change your .htaccess file or your server does not support mod_gzip or mod_deflate then you can change your HTML files to PHP files and then add the following code at the top of the page

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

With this code you are sort of setting up your own server – you are telling it to accept the encoding and return a gzip file otherwise the regular version.

Its as simple as that. I would recommend trying to use the .htaccess way if possible but if not then change to php. The results are great and can reduce your page size by 70%.

A few things that you will need to consider when doing this.

Firstly when you rename your files from .HTML to .PHP then you will need to update all internal links to point to these pages. From a SEO perspective this would mean that your url has changed and any backlinks pointing to the old .HTML pages will return a 404 not found error. This ultimately means that the backlinks you created will be pointing to a place that does not exist and your new url will have no backlinks pointing to it. You can however do a server side redirect but from previous experience its not very effective – still better to do it then not.

One thing that I would recommend is to create future websites using the PHP extension and not HTML

Once you have added the coding to your PHP file or have enabled server side compression then you should go and check it has worked.

You can do this by

Online:-going to www.whatsmyip.org/http_compression and entering your url

Through your browser:- if you have the web developers toolbar then you can go to information>view document size and see if the size has reduced

Here are a few useful pics that I found which should explain how Gzip compression works – Any questions then please feel free to post

non compressed

gzip compression

Tags: compression, gzip, speed up website

Comments are closed.