When optimizing a website’s performance, the very first thing you should check is whether or not your site is taking advantage of GZIP Compression.
What is GZIP
The Cole’s notes of what is GZIP, is that GZIP Compression is a mechanism where the server compresses the requested web page, image, or other file, before serving it to the browser. If you’ve ever “zipped” up file for archiving, or before sending it in an email, it’s the same concept.
As soon as the file has been received by the web browser, it decompresses it and then uses it, either to display, or to render aspects of the page.
How To Enable GZIP
Depending upon the type of web server that you’re running, there are different ways to enable GZIP compression. In this article, we’re going to go over enabling GZIP on the Apache web server platform.
Step #1: Test Your Web Page
One of the tools we use to test a web page is checkgzipcompression.com. Test out your home page to see how big it is, and how much can be saved by compressing it. In many cases, HTML pages can be compressed by over 50% if they are not already compressed with GZIP.
Step #2: Enable GZIP with .htaccess file
Apache technically has two possible compression options available, in most cases. Depending upon your web sever, and how it is configured, you may have on or the other installed. The code below covers both compression mechanisms.
In the root folder of your website, create a file called “.htaccess” (yes, that is a dot before the ‘h’), if you don’t already have one. At the very beginning of that file, add the following code:
In the first section of the code you’ll see a special conditional tag <IfModule mod_gzip.c> and then later, a closing conditional tag </IfModule>. What these tags do is tell the server that is the module “GZIP” is installed, then use the enclosed code.
You will also see that there is a second set of conditional tags that surround the code that would be used if the server has the “DEFLATE” module installed instead.
Once you’ve placed the code in your .htaccess file, save it, and then upload it to the website root in your live site.
Step #3: Test Your Compressed Page
Head back to checkgzipcompression.com — you should now be able to test your home page and see that it is now compressed with GZIP and by how much. This can immediately impact how fast your web pages load, and help to boost your Google PageSpeed score by as much as 15 points.