Enable Compression

Enable Compression

This is part of our guide on improving page speed using the Google page speed insights developer tool. In this article we are discussing how to enable compression. We will be writing this article for novices using plain English and attempting to add a little more light to the explanation given by Google.

What is Enabling Compression?

A compressed file has had its memory reduced and therefore uses less memory. You may have come across some popular formats of compressed files that end in .zip or .rar. Almost any file can be compressed in this manner from images to program files but although these files are much smaller, they are unable to be used until they have been decompressed by the appropriate software (winzip or winrar etc).

 

Why Enable Compression on your website?

Well as we said compressed files use less memory so if you compress your site it will take less time for the user’s browser to download.  Web browsers are able to decompress the files and show them in their original state. This gives website owners a great opportunity to increase the download speed of their site and improve user experience. Many site owners already use compression so if you are not you are at a disadvantage.

The two most common compression tools are GZIP compression and Deflate compression. Gzip  and Deflate have their different advantages and sometimes it is an advantage to use one over the other (1and1 prefer to use the Deflate code shown below for example).

 

How to Enable Compression

There are several ways of enabling compression the most common being using your .htaccess file on apache servers or your web.config file if you are on a windows server. This method works whether you are using shared hosting (allocated space on a server) or if you have a dedicated server. Because of this I will show you these methods for enabling gzip and deflate compression.

Enable Compression using .htaccess file

(if you don’t have a .htaccess file and are not sure how to create one then check out this tutorial)

Insert the following into your .htaccess file

# BEGIN GZIP
# mod_gzip compression (legacy, Apache 1.3)
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|xml|txt|css|js)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP

Enable Deflate Compression on 1and1

Copy and paste this into your .htaccess file

<IfModule mod_deflate.c>

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/svg+xml

</IfModule>

And once uploaded that is it. Congratulations, your site is now compressed. That’s another tick and an increase in points for your google pagespeed insights results.

To learn more about Google pagespeed insights tool and follow our guide on improving pagespeed please click on the link below.

 Improving page speed using the Google page speed insights developer tool