Faster website access using Mod_Deflate Compression

By: Published: Jan 19th, 2013 Category: Apache

There are many reasons for a website to run slow one of them is heavy content i.e. the website content received by client (browsers) is larger in size and on slower connections this could be a nightmare. Now using Mod_Deflate you can compress the size of files before delivering it to clients. Mod_Deflate is based on a class of data compression algorithms called Deflate that allows the exact original data to be constructed from the compressed data. Mod_deflate drastically reduces/compresses the files which are sent to Client (you can imagine the speed to load 26KB file instead of 120KB of your website).

Mod_Deflate Installation

Before You start using Mod_Deflate you need to checkĀ  its installed on web server or not. If you have root level you can check that by using command “httpd -l” which lists all the modules which are compiled with Apache Web Server. (shared server users will have to contact their hosting company to check)

root@server [~]# httpd -l | grep deflate
mod_deflate.c
root@server [~]#

Or you can check the httpd.conf and try search for following rule in LoadModule

LoadModule deflate_module modules/mod_deflate.so

If you won’t find mod_deflate using above steps Apache is not compiled with mod_deflate, please contact your Webhosting company to re-compile the Apache with it. If you have Cpanel server with root level access you can recompile Apache with mod_deflate using EasyApache.

Enable Mod_deflate

Mod_deflate can be enable for the complete server were all the websites hosted on the server will be compressed automatically or you can enable is for specific websites using .htaccess only.

Server Wide

If you have the root access of the server add following lines in httpd.conf file of your server which will enable the mod_deflate server wide.

<Location />
<IfModule mod_deflate.c>
#compress content with type html, text, and css
AddOutputFilterByType DEFLATE text/html text/plain text/css
<IfModule mod_headers.c>
#properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>
</Location>#Handle old browsers that do not support compression
<IfModule mod_deflate.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
</IfModule>

Restart the web server to apply the settings.

Domain wise

This is very useful for shared hosting customers where they can’t have the root level access.

Now go to home directory of the domain and open (if exists) or create a new file named .htaccess and add following line.

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
#End Gzip

Once its configure now its time to check if its working or not; browse http://www.whatsmyip.org/http_compression/ and enter the website hosted on the server to test.

 Faster website access using Mod Deflate Compression

About 

Milind Koyande is a Project Manager and his job is to work with new technologies, specially Cloud Computing / Virtualization Technology. His past projects include Government Sector initiatives, Backup and Disaster Recovery Solutions.

Tags: , , , ,

One Response to “Faster website access using Mod_Deflate Compression”


  1. Faster website access using Mod_Deflate Compression « .:][ Gr8 Admin Team ][:.
    on Jul 27th, 2011
    @ 8:45 am

    […] Mod_deflate drastically reduces/compresses the files which are sent to client (browser) and this post tells how you can configure it to improve your website performance Amplify’d from eitwebguru.com […]

Leave a Reply

Subscribe to eITWebguru

© 2012 eITWebguru. All Rights Reserved.