Speeding up your Apache hosted website through mod_deflate on Debian / How to compress css and (js) javascript

People who run websites which aim at top responce times, are quite familiar with mod gzip and mod deflate .
Both Apache modules mod deflate and mod gzip are used for the very same purpose. They add a standard gzip compression to the files that Apache transfer to your Webserver clients.

Its said mod_gzip is the more powerful and more configurable module, however most people nowadays stick to the more straigh forward and easier to set up mod_deflate

I personally also adhere to mod_deflate since it’s documentation on Apache’s website is quite complete.

In this article I’m gonna explain you how I quickly added support for mod_deflate gzip compression to a Webserver I’ve recently had to configure for a website.

Doing so reduced the access time to the website from 6-7 seconds as reported by Yahoo’s Yslow to 3-4 secs.

These days people are constantly looking for a ways to improve their web site opening times in order to improve the end user experience, so the reduce to about 3 seconds in a website access time is quite a good achievement.

Some time ago I’ve blogged about How to enable http gzip compression on CentOS 5.x to speed up Apache

However I’ve realized I haven’t blogged how the same thing is achieved on a Debian Linux so therefore I decided it might be interesting to somebody out there to explore how same thing is achieved on Apache server running on top of Debian.
Anyways enough jabberish, here is the exact steps I took on a Debian Lenny server to configure properly an Apache 2.x webserver gzip compression through the mod_deflate module.

1. Open up /etc/apache2/mods-available/deflate.conf and place the following configuration directives within the file:

<IfModule mod_deflate.c>
# AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml application/rss+xml application/json text/css text/javascript application/javascript application/x-javascript
# Insert filter
#SetOutputFilter DEFLATE

# Netscape 4.x has some problems
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

# Don’t compress images
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary

# Don’t compress already compressed stuff !
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary


Note that above configuration has an extra configuration directives to AddOutputFilterByType DEFLATE which are gonna instruct it to also gzip compress content of the CSS and Javascript (js) files as well.

2. Shut off Etags in /etc/apache2/apache2.conf the quickest way to do it would be:

debian-server:~# echo "FileEtag none" >> /etc/apache2/apache2.conf

3. Enable mod_deflate in your Apache server

debian-server:~# ln -sf /etc/apache2/mods-available/deflate.conf /etc/apache2/mods-enabled/deflate.conf
debian-server:~# ln -sf /etc/apache2/mods-available/deflate.load /etc/apache2/mods-enabled/deflate.load

Now you need to restart your Apache server for the changes to take affect.

debian-server:~# /etc/init.d/apache2 restart

This changes are also about to include the common suggestion by Yahoo Yslow that warns about the following message:
Grade D on Compress components with gzip

There are x plain text components that should be sent compressed

Thus the aforementioned changes to your Apache would guarantee you also a good compression status in Yslow web site slowness test.
After the changes the returned message by Yslow would be:

Grade A on Compress components with gzip

By the way it took me quite a lot of time to search for a solution to the annoying yslow issue where the .css and .js scripts failed to be compressed with gzip nevertheless the mod_deflate module was active.
I therefore hope this post will help somebody else issuing the Yslow css and javascript not being compressed issues to get solved.

Share this on:

Download PDFDownload PDF


9 Responses to “Speeding up your Apache hosted website through mod_deflate on Debian / How to compress css and (js) javascript”

  1. Natalie says:
    Opera 9.64 Opera 9.64 Windows XP Windows XP
    Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1

    Helpful blog, saved your site for interest to read more!

    View CommentView Comment
  2. Brittany says:
    Firefox 3.0.14 Firefox 3.0.14 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2009082707 Firefox/3.0.14 (.NET CLR 3.5.30729)

    The nice summary assited me very much! Saved your site, extremely great categories just about everywhere that I see here! I really appreciate the information, thank you.

    View CommentView Comment
  3. Theme Spice says:
    Google Chrome Google Chrome Windows 7 Windows 7
    Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome/ Safari/532.2

    found your site on del.icio.us today and truly liked it… i bookmarked it and will also be back to ascertain it clear out some more later ;-p

    View CommentView Comment
  4. Jonas Santaella says:
    Internet Explorer 7.0 Internet Explorer 7.0 Windows XP Windows XP
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

    The content on this article is really 1 of the most beneficial material that We have ever appear across. I love your article, I’ll are available back to examine for new posts.

    View CommentView Comment
  5. Jefferey Adney says:
    Firefox 3.8 Firefox 3.8 Ubuntu 9.25 Ubuntu 9.25
    Mozilla/5.0 (X11; U; Linux i686; it-IT; rv: Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8

    I like the way you make use of words in order to create something very interesting to read. The message flows naturally, no heavy language or clichés are present. This is exactly how a well-researched, nicely written piece of information should look like! I am already back for more…

    View CommentView Comment
  6. CooL Site says:
    Firefox 3.0.14 Firefox 3.0.14 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2009082707 Firefox/3.0.14 (.NET CLR 3.5.30729)

    I really like your writing style, fantastic info , regards for putting up : D.

    View CommentView Comment
  7. Dez Maine says:
    Opera 9.64 Opera 9.64 Windows XP Windows XP
    Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1

    Excellent. Thanks.

    View CommentView Comment
  8. admin says:
    Opera 11.00 Opera 11.00 GNU/Linux x64 GNU/Linux x64
    Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.7.62 Version/11.00

    Besides speeding up mod_deflate enabling saves bandwidth for both server and client side. The only downside of it is it puts very little extra CPU load. On webservers which are serving huge files in size, enabling mod_deflate is not a good idea. However for most websites it can only do good.

    View CommentView Comment
  9. Mitsue Ikemoto says:
    Unknown Unknown Unknown Unknown

    First time visit here and have your excellent short article. May I’ve a copy of the guide?

    View CommentView Comment

Leave a Reply

CommentLuv badge