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.
- mod_deflate (recommended way)
You will need to add the following lines to your .htaccess file:
Make sure mod_gzip module should be enabled.
Create a file at /etc/nginx/conf.d/gzip.conf with the following content:
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:
curl -H "Accept-Encoding: gzip" -I https://www.techpulsetoday.com/
You should see content-encoding: gzip