Speeding Up the Site With Apache GZIP Compression

We can speed up the site with compression while save bandwidth at the same time. As most of the modern browsers support gzip encoding, we can set it up to let the users enjoy faster speed. The Apache mod_deflate is easy to set up and standard. It compress the content on the fly.

We can enable output compression in Apache by adding the following into the .htaccess file in the root directory of the website:

# Compress html, text, javascript, css and xml content:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/x-javascript

If the .htaccess file can’t be edited or the mode isn’t enabled, there is another alternative solution for php supported environment:

Speeding Up the Site by Using PHP GZIP Compression

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.


  1. Hi I am using this gzip,

    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

    what is the difference with the one you are showing on you blog?



    1. Hi Richard,

      Your method uses the mod_gzip module.

      The method in this post uses the mod_deflate module. The method in this post explicitly exclude files by MIME types only.

      Both methods should be okay if they works well. For the compression rate, both methods, generate roughly the same one (mod_gzip is slightly better).

Leave a Reply

Your email address will not be published. Required fields are marked *