Everyone wants a faster website. In fact, website performance is one of the key attributes used by Google when turning up search results. If a page takes longer than 4-5 seconds to load, most web surfers today abandon it and move to another site. One of the most powerful methods of serving your site faster is to incorporate GZIP compression.

What is GZIP Compression?

In a nutshell, GZIP compression allows your website to compress large files before sending them to your visitor. Smaller files transfer quicker, and the visitor’s web browser simply unzips them on the receiving side. GZIP compression can shink the network traffic needed to view your website by as much as 80%!

How about Mod Deflate?

Mod Deflate is another compression scheme similar to GZIP.

Are You Using GZIP?

Depending on your web host, you may have GZIP enabled and not even know it. Before making changes, test your website URL at WhatIsMyIp.org. If the tool returns that you’re using compression, then there’s nothing else for you to do (unless you want to try different compression types). If the tool shows no compression on your website, keep reading…


Unsplash

Enable GZIP Compression

In some cases, you’ll have to ensure that your host has one of these compression methods available. Typically, if you access your hosting account using CPanel, you can check the Optimization menu to make sure your account is set to compress all files. After that, you’ll still have some work to do in your .htaccess file. You might have to check with your host just to be sure.

Modify .htaccess

For Apache Servers:

Add the following line to your .htaccess file:

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

Alternatively, you can add this block of code if you expect significant traffic from older browsers:

<ifmodule mod_deflate="" c="">
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml</ifmodule>

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

For Servers using NGINX

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;

Windows/IIS Servers

If your site happens to be running on IIS (a Windows-based web server), then follow these instructions for enabling GZIP.


 

Sharif Jameel

Sharif Jameel is a business owner, IT professional, runner, & musician. His professional certifications include CASP, Sec+, Net+, MCSA, & ITIL and others. He's also the guitar player for the Baltimore-based cover band, <a href="https://www.facebook.com/LiquifactionSounds/">Liquifaction</a>.

Leave a Reply