PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » HTAccess » Active Gzip Compression

Active Gzip Compression

Compression reduces response times by reducing the size of the HTTP response. Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim to support gzip.

# BEGIN 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

Subscribe to The Thread

  1. What happens to the 10% who don’t support it?

  2. Peter Dubrovski

    Under Apache 2 better use mod_deflate

  3. I’ve never understood how to get GZIP working. By just copying this into the .htaccess it will GZIP all my content?

    • Some server don’t support it. This might be the reason, why it’s not working for you. The example above will compress the follwing file types:
      - text
      - html
      - xml
      - css
      - js

      Important is not the file extension, but how the server handles the files. Images – no matter what format – will not be compressed with this setting. This wouldn’t make sense, because all image types already use compression in one way or the other. And these compression methods are much more effective in handling bitmaps (image data).

  4. Does this have a downside?
    What happens in browsers which do not support gzip when using this?

  5. Warrick

    I have a question as a .htaccess noob.

    How does this code work?
    I have added it to mu .htaccess file and Yslow in FireBug says that I do not have gzip compression?

    Any ideas

  6. i want to know where is the located .htaccess file where is put this above code and also tell me whats the procedure to do this gzip/deflat integration.

  7. i have add that string but did not work. my server use apache 2

  8. D. Schmitz

    I use this one for gzip and deflat


    # BEGIN GZIP
    # mod_gzip compression (legacy, Apache 1.3)
    <IfModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|xml|txt|css|js)$
    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.*
    </IfModule>
    # END GZIP

    # DEFLATE compression
    <IfModule mod_deflate.c>
    # Set compression for: html,txt,xml,js,css
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
    # Deactivate compression for buggy browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch bMSIE !no-gzip !gzip-only-text/html
    # Set header information for proxies
    Header append Vary User-Agent
    </IfModule>
    # END DEFLATE

    what do you think about this code?

  9. I use this to gzip my php pages
    php_value output_handler ob_gzhandler
    it doesn’t work with flush() in php
    does any compression work with flush()

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~