Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to compress the JS and CSS (perhaps also html?) files that I'm sending out. I've read a lot about gzip and mod_deflate but I'm not really sure what's the best to use?

I'm looking for the easiest thing to maintain and to reduce bandwidth on my web app.

share|improve this question
up vote 3 down vote accepted


mod_deflate is the module available to achieve Gzip compression in Apache2.

mod_gzip in Apache1 has been replaced with mod_deflate in Apache2.

It does a really good job at compressing.

Sample config

Here's a sample configuration which compresses HTML, CSS, JS, RSS (depending on the browser):

<IfModule mod_deflate.c>
          # these are known to be safe with MSIE 6
          AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xhtml+xml

          # everything else may cause problems with MSIE 6
          AddOutputFilterByType DEFLATE text/css
          AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
          AddOutputFilterByType DEFLATE application/rss+xml

      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.0[678] no-gzip
      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

      DeflateFilterNote Input input_info
      DeflateFilterNote Output output_info
      DeflateFilterNote Ratio ratio_info
      LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
      CustomLog /var/log/apache2/deflate_log deflate


Also, here's a tutorial about mod_deflate for Apache2.

share|improve this answer
to be safe for everything from IE6 and up, is this a valid sample config? worried about "# everything else may cause problems with MSIE 6" ? – solsol Jun 22 '10 at 22:19
Well the BrowserMatch should restrict to compressing only the html for IE. I haven't tested it though. – Weboide Jun 23 '10 at 10:30

It looks like mod_gzip was renamed to mod_deflate in Apache 2.

Of note in the article is that anything under 1K in size isn't really worth compressing. The mod_deflate page states that it doesn't compress images either (I'd post the link but I lack the reputation).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.