Logo Background

Web Tuning Using Apache Mod Deflate Compression

  • By on October 27, 2008 | 2 Comments

    It’s possible with the Apache web server to compress files that are sent to the browser so less bandwidth is consumed and the load time should generally be faster. The module in Apache 2.0 and up is called mod_deflate and for older versions of Apache there was, what I recall as being, a third party module called mod_gzip.

    To enable the gzip compression on your files, open your .htaccess in your files and add in the mod_deflate module for Apache compression

    <IfModule mod_deflate.c>
    <FilesMatch ".(js|css|html|htm|php)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>

    This goes in your root .htaccess file but if you have access to httpd.conf that is better.

    This code uses the FilesMatch directive and the SetOutputFilter DEFLATE directive to only target files ending in .js or .css or .html or .htm or .php

    Some file types are already compressed, such as graphics files, music files and related, so you shouldn’t attempt to compress those files types. Generally it will just be text files that you would want to compress.

    But compressions takes up additional CPU cycles and memory at both the server and the client, so you need to be careful about what you compress. For example it may be much better to leave HTML, CSS or JavaScript files served in their normal state if they are quite small anyway because the overhead required to compress and decompress may not justify the small amount of bandwidth savings.

    Previous
    Next
    » Reset Windows Password Using Chntpw
  1. #1 Jayce
    January 25, 2011 7:07 am

    Just wondering… Why most of the time this compression does not work on your blog at Bluehost and my blog at HostMonster and Just Host? But it is working perfectly on HostGator with the same configuration.

    Post ReplyPost Reply
  1. #2 Jing Hong
    January 26, 2011 9:34 pm

    I found the same problem as well after analyzing using Google Page Speed. It works 70% of the time and sometimes it just didn’t do any compression at all. Weird.

    Post ReplyPost Reply
Leave a Comment