How to enable Gzip compression

What is Gzip compression?

GZip Compression (compress) all files like HTML, JS and CSS files while serving the request to the browser; it doesn’t make any difference what the file type is or the encoding. As a size of the file is reduced it is served to the user in a faster manner. Not all the browser support compression but now all the modern browser support. It is highly recommended, but only one part is that it increases the CPU usages of the server which may be concern sometime. Using Gzip with client side caching will help in increasing the performance.

How to enable Gzip compression?

Here are the most common ways to enable gzip compression including .htaccess, Apache, and Nginx web servers.

For Apache:

  1. mod_deflate (recommended way)
  2. mod_gzip

You will need to add the following lines to your .htaccess file:

mod_deflate Method:

mod_gzip Method:

Make sure mod_gzip module should be enabled.

For Nginx:

Create a file at /etc/nginx/conf.d/gzip.conf with the following content:

Restart Nginx:

You can use the Forge Nginx restart dropdown, but since you’re SSH’ed in you can also just run sudo service nginx restart.

To test if gzip compression is enabled, run:

You should see content-encoding: gzip

Vijayan J

Thanks for stopping by guys! I’m Vijayan and Techpulse is my beloved brainchild.
Currently working as a PHP developer in a digital marketing start-up, I’m overly passionate about not just learning new things but also putting those into practice. I swear by a quote I once came across…
‘What separates successful people from unsuccessful people is the former’s ability to execute’.
Feel free to reach out to me if you have any questions, suggestions or feedback. Hoping to see more of you here!