What is GZIP Compression?
How does GZIP compression work?
Developers from Google – Simply put, gzip compression works by finding similar strings within a text file, and replacing those strings temporarily to make the overall file size smaller. This form of compression is particularly well-suited for the web because HTML and CSS files usually contain plenty of repeated strings, such as whitespace, tags, and style definitions.
How to enable GZIP Compression with the .htaccess file on Apache Webservers
You can enable GZIP by simply adding a bit of code to the .htaccess file on your webhost / server. The code below will enable it on your server.
Note: If you are not familiar with the .htaccess file please read this excellent article on feedthebot.com: How to use the .htaccess file
How to enable GZIP Compression on NGINX Webservers?
By adding the following code to your config file you can enable GZIP.
Enabling GZIP with PHP
It is also possible to enable GZIP using PHP. This can be useful if you are not able to access or use an .htaccess file on your webhost/server.
The following code snippet should be used at the top of your PHP pages. (Don’t forget to place it between the PHP tags)
<?php ob_start('ob_gzhandler'); ?>
How to test if GZIP is working for your site?
It’s very easy to test if GZIP is correctly working on your site by simply checking the URL in any of the numerous tools online. One example of this is this tool by Small SEO Tools.
Some resources with more information on GZIP: