A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Code Snippets > HTAccess > Active Gzip Compression Submit one!

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. Ben says:

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

  2. Peter Dubrovski says:

    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?

    • NetHawk says:

      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. John says:

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

  5. Warrick says:

    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. Mehul says:

    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. rahmat says:

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

It's Your Turn

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