How To: Compress web page data transfer with mod_deflate and mod_headers

Since I rebuilt my VPS the other day there a number of tweaks and changes I need to make which can speed up the website – one of the easiest ones with the biggest effect on pageload time is to have apache serve compressed versions of pages to users. Here’s how to do it, and test that it’s working.

Enabling mod_deflate and mod_headers

Chances are good that you already have mod_deflate and mod_header on your server (they typically come with the apache install) – so all you need to do is enable them. To do so, open your main apache config (for example, on mine it’s /etc/httpd/conf/httpd.conf and uncomment the LoadModule lines for each module, so that they end up like this:

With that done, you can head down to the bottom of the config file and add the following section to enable compression of all html, css, js, xml and such.

Restarting apache and testing it out

With those changes made, save the file, restart apache (for example, via: sudo systemctl restart httpd.service if you’re on a systemd-using machine), and then go to: http://www.whatsmyip.org/http-compression-test/

Plug in your URL and hit submit, and you should see some good news similar to this:

A page saying that we are successfully serving compressed webpages.

Very nice =D

Many thanks to: brighterlamp.com for the original article this one is based on.

Leave a Reply

Your email address will not be published.