Enable compression (gzip compression) – Apache Server (httpd)
If you are transporting enough textual data from server to browser, Enabling compression can do some thing for you in making your website faster. A good example is making tables of entities which is very normal and unavoidable screen in any web application. In these kind of screens you generally transport 10s, 20s, 50s or 100 rows of data of certain entity from server to Browser.
If you have weak connection but good CPU you can take benefit of gzip compression which can be easily enabled on Apache Web Server. After enabling compression on Apache server, all responses coming through apache server will be compression using gzip compression and Browser has to decompress the data before rendering it.
How to enable gzip compression – apache server (httpd) ?
1. Locate configuration file for apache server (generally at /etc/httpd/conf/httpd.conf)
2. LoadModule deflate_module modules/mod_deflate.so — Search this line in configuration file and un-comment it , if commented.
3. Add following lines in Configuration file:
<IfModule mod_deflate.c> SetOutputFilter DEFLATE # file-types indicated will not be compressed SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary <IfModule mod_headers.c> Header append Vary User-Agent </IfModule> </IfModule>
4. Add following lines to change expiration settings of images and htmls
<IfModule mod_expires.c> # enable expirations ExpiresActive On # expire GIF images after a month in the client's cache ExpiresByType image/gif "access plus 1 month 15 days 2 hours" #Test that cached version is not used for the request ExpiresByType text/html "access plus 30 seconds" #Check with cached version #ExpiresByType text/html "access plus 30 days" </IfModule>
5. Create a log file to check compression results:
<IfModule mod_log_config.c> <IfModule mod_deflate.c> DeflateFilterNote Input instream DeflateFilterNote Output outstream DeflateFilterNote Ratio ratio SetEnvIf Request_URI \.gif image-request SetEnvIf Request_URI \.js image-request SetEnvIf Request_URI \.css image-request LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate CustomLog logs/deflate.log deflate env=!image-request </IfModule> </IfModule>
6. Please check all the modules used above should be loaded (un-commented in config file).
mod_deflate
mod_log_config
mod_expires
mod_headers
7. Restart apache server by running following command:
#apachectl stop #apachectl start
8. You can start monitoring the log file for compression results or check the content-type encoding of response at Browser using some plug-in like Firebug on Mozilla Firefox.
Most Commented Posts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

[...] you have no idea about how to enable Deflate module Sitepoint and Techie Gyan article explains how to do [...]