Rietta: Web Apps Where Security Matters
You are reading The Rietta Blog, a publication about the web since 2005.

Mod_deflate: Dramatic Website Speed Increase With Apache Compression on Ubuntu Linux

Last Updated on October 6, 2013. This post is one of the most visited on this blog and is a maintained post that is periodically updated to be most useful to you. For more, see the list of all maintained posts.

It’s easy to dramatically improve the loading speed of your website by enabling compression support in your Apache web server. This works without needing to make any changes to your backend or database code no matter what programming platform your development team uses.

I recently added this change to a Ruby on Rails-based web application running on a Ubuntu Linux dedicated virtual server. That particular page observed a 72% decrease in bandwidth required to deliver the homepage.

It has been my experience with our internal and with client RoR sites that mod_deflate tends to provide a 62% to 72% savings on bandwidth required to deliver each page. This is significant for visitors on slower connections or mobile phones. It is well worth enabling for most applications.

Three Easy Steps

Step 1: Enable mod_deflate in your Apache2 installation

sudo a2enmod deflate

Step 2: Edit /etc/apache2/httpd.conf to configure mod_deflate to compress certain file types

<IfModule mod_deflate.c> 
  # compress text, html, javascript, css, xml: 
  AddOutputFilterByType DEFLATE text/plain 
  AddOutputFilterByType DEFLATE text/html 
  AddOutputFilterByType DEFLATE text/xml 
  AddOutputFilterByType DEFLATE text/css 
  AddOutputFilterByType DEFLATE application/xml 
  AddOutputFilterByType DEFLATE application/xhtml+xml 
  AddOutputFilterByType DEFLATE application/rss+xml 
  AddOutputFilterByType DEFLATE application/javascript 
  AddOutputFilterByType DEFLATE application/x-javascript 
  AddOutputFilterByType DEFLATE image/x-icon 

Step 3: Restart Apache to enable the changes

sudo apachectl graceful

Test if it Worked

Once you have made the changes, test if the deflate is working properly by browsing through the website with all of your browsers. Then confirm that the connection is running deflate using a third party tool. One such is http://www.whatsmyip.org/http-compression-test/.


Invitation to the Web Application Topics Newsletter

This post is part of the Web Application Topics series. If you are interested in having future issues sent directly to you by e-mail, please sign up for free, today. For back issues, see the Web Application Topics category on this blog.

Revision History

As a maintained post, this document is updated from time to time.

  • October 6, 2013: Promoted to a Maintained Post status
  • September 3, 2013: Reformatted as part of the migration to the new blog.
  • April 18, 2012: Originally posted on The Rietta Blog, hosted on the Blogger platform

About Frank Rietta

Frank Rietta's photo

Frank Rietta is specialized in working with startups, new Internet businesses, and in developing with the Ruby on Rails platform to build scalable businesses. He is a computer scientist with a Masters in Information Security from the College of Computing at the Georgia Institute of Technology. He teaches about security topics and is a contributor to the security chapter of the 7th edition of the "Fundamentals of Database Systems" textbook published by Addison-Wesley.