2

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.

solsol
  • 1,121
  • 8
  • 21
  • 31

2 Answers2

3

Introduction

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

Tutorial

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

Weboide
  • 3,275
  • 1
  • 23
  • 32
  • 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
1

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

http://developer.yahoo.net/blog/archives/2007/07/high_performanc_3.html

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

Tyler K
  • 256
  • 1
  • 6