Tag: gzip compression

ENABLE COMPRESSION

SEO is more competitive than ever and the days of spamming Google are pretty much gone. Search engine companies have done an excellent job of helping users find the most relevant returns for a given query. They simply know what good content is and, for the most part, they know how to filter out the garbage. To rank well, you have to provide truly valuable content.

In addition to providing something useful, you have to provide it a way that respects mobile devices and is FAST.

Taking the time to refine site speed has pretty big payoffs and may be the thing that puts you above your competition. There are many things that can be done (minifying js/css/html, minimize server requests, sprite sheets etc…), and time permitting I’ll go into more detail, but this particular post is about one thing – compression.

Enable Compression

Google’s PageSpeed Insights will let you know if your site is not using compression. As of January 2015, it is likely that you are not.

So how do we enable compression?

I’m a LAMP guy. Linux/Apache/MySQL/PHP. If you are too, chances are mod_deflate is already enabled. I assume you know how to use phpinfo() to determine how your site is configured.

Enabling mod_deflate is only part of what needs to happen. You also need to edit .htaccess.

A quick search on StackOverflow reveals this post: http://stackoverflow.com/questions/12367858/how-can-i-get-apache-gzip-compression-to-work

Of all the suggestions, Oussama’s is the one that worked for me. Simply add this to your .htaccess file:

# Enable GZIP

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary

Now use PageSpeed Insights to review your site again. You should see that you’ve made Google happy and your site score improved.