Speed up your site with Gzip Compression
Speed up your site with Gzip Compression
Website loading time matters a lot for every big website or blog. Gzip compression allows you to fasten up your website with just a few lines of code in your htaccess file. When you are on a shared hosting it matters a lot to have a fair loading speed. Gzip compressions can speed up your website from 50% to 70%.
Google Speed Tools provides various techniques to speed up your web page. There is also a page service called ‘Page Speed Service’ from Google. Page Speed service uses mode_pagespeed i.e. an apache module for your server which automatically tweaks your pages and server a better and optimized code to the browser.
Coming to the Gzip compression, you can use the mod_deflate module (Apache 1.3x used mod_gzip but since Apache 2x mod_deflate is used). You just need the following line of code to enable Gzip compression for your website.
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html
</IfModule>There is also a method to speed up loading speed of your website using browser caching. You can use Page Speed Online to analyze the factor that are causing your website to load slow. There is also a plugin for Chrome and Firefox. Following snippet sets an expire date for specified files and reduces errors on the page resulting in faster load time.
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>Using Cache control for web pages also speeds up the website, code for the same are as follows:
<ifModule mod_headers.c>
<filesMatch ".(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch ".(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch ".(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch ".(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule> Few of you, may notice that I have not defined max-age for the file types but in our mod_expires module we already have defined it. Mix up all the code and analyze your web page using Page Speed Online and you will notice that your website is working faster than ever.
You can view htaccess Gzip Compression Gist for full code.
Want to know more about Gzip? Read more about Gzip at Wikipedia.

