Speed up your website using GZip Compression

Hi guys!

Google and Yahoo! use Gzip compression for faster content delivery. Of course, you all guys know how fast google is . It is the webserver that enables the compression for web pages. Google uses its own web server. However, this can be achieved using Apache webserver as well.

If you apply compression, the website html file size can be significantly reduced when delivering to the browser. All modern browsers support gzip compression . Using Gzip we can compress html files anywhere from 40% to even 90% !

The compression also saves your bandwidth! Since the transferred file size is less, your site will load faster.

An example , the home page of my website http://www.vivekv.com

Without compression : 11 kb

With compression : 4 kb

That is 60% difference!

 

Apache actually has two compression options:

  • mod_deflate is easier to set up and is standard.
  • mod_gzip seems more powerful: you can pre-compress content.

 

Method 1:Using .htaccess file

Just append this code to your .htaccess file and you’re done

<Files *.html>
SetOutputFilter DEFLATE
</Files>

 

Method 2. Using PHP

If you can’t change your .htaccess file, you can use PHP to return compressed content. Just add this php code immediately after the first <?php open tag.

In PHP:

[php]
if (substr_count($_SERVER[‘HTTP_ACCEPT_ENCODING’], ‘gzip’)) ob_start(“ob_gzhandler”); else ob_start();
[/php]

We check the “Accept-encoding” header and return a gzipped version of the file (otherwise the regular version).

Once done, you can verify the compression using this GzipTest website

Try it guys!

 

2 thoughts on “Speed up your website using GZip Compression

Leave a Reply

Your email address will not be published.