Skip to content

How To Enable Gzip Compression

April 8, 2014

Whenever someone visits your website, your website’s server will deliver all the required files (text, CSS, HTML, etc) to the visitor’s computer. Logically, the bigger the files, the longer it takes for your website to load on your visitor’s computer.

The main reason why gzip is important is because it speeds up file transfer speeds by reducing the size of your page elements, which translates into faster website loading times.

Gzip is a server-side technology that automatically compresses some of your webpage elements before sending them over to the visitor’s browser. This reduces transfer times significantly since the files are much smaller.

If you are wondering about whether or not to implement this, you should. There’s no difference in visitor experience (besides faster page loads), no conflicts, and a very simple setup process.

How Does Gzip Work?

Gzip compression works by replacing similar strings within a text file temporarily to reduce the overall file size. As such, gzip works best for text-based files, such as HTML and CSS files.

To use gzip, it has to be enabled on your web server, and all modern browsers will support gzip. A visitor’s browser will request and receive the gzip version of your website elements, and if the browser does not support gzip, then it will just receive the regular version.

How To Setup Gzip

Here are ways to setup gzip for 2 common webservers (Apache, and Windows IIS).

For Apache

Gzip can be easily enabled through your .htaccess file (in your root folder):

####################
# Gzip compression #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/plain text/html text/css text/xml application/x-httpd-php application/x-javascript
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip

For Windows IIS

If your server is IIS, follow these instructions in the Microsoft TechNet document to enable compression.

http://technet.microsoft.com/en-us/library/cc771003%28WS.10%29.aspx

Related Posts.