Hello, friends, today’s topic is how to enable GZIP compression on your web server. If you guys know what is GZIP and how to enable it, that’s good but those who don’t know please read this tutorial till the end.
What is GZIP Compression?
GZIP compression never work on images because these are compressed in a different way
How we check GZIP Compression enable or not?
Don’t worry, this is not a complicated task, you can check this on your browser and all browsers support this. We have to just check content-encoding: gzip HTTP response header in browser Devtool. If it is active, it means GZIP is enabled on your website. Let me show you in the screenshot.
According to the screenshot above, GZIP compression is enabled on the website.
How we enable GZIP Compression?
There are two methods to enable GZIP compression, First one is from the server and the second is from the website .htaccess file. Basically is a mod_deflate, if this enables from the server then you can just add the script in the .htaccess file that’s it. If not then you have enabled it from the server either from cPanel or WHM.
First, we will see how we enable mod_deflate from cPanel, check below screenshots steps by steps:
- Login to your cPanel account, Go to the Software section and click MultiPHP INI Editor, see below screenshot
- Now you are in MultiPHP INI Editor page, Select your domain on which you need to enable deflate, see screenshot below
- Once you select your domain, available PHP Directives will show in the bottom. You have to find zlib.output_compression, enable it and hit the Apply button. See below screenshot…
Above we saw how we enabled GZIP compression or the deflate but what happen if this PHP Directive is not available in your cPanel. Ok, don’t worry, we will walk you through this. If we have WHM access then below steps will help to enable GZIP Compression if you don’t have WHM then ask your hosting support.
Let’s see the WHM steps to enable GZIP Compression, please follow the screenshots they will help you more…
- Login to your WHM, search EasyApache in the search bar and click on EasyApache 4, see screenshot…
- On the EasyApache 4 page, we have to customize cPanel. Click Customize button of cPanel Default box, see screenshot…
- Once you are on cPanel Customize page, Apache Modules >> search deflate >> enable mod_deflate. Once you enable it, click Review tab, follow the screenshot below…
- After clicking Review tab >> scroll down click Provision button >> wait till the process end>> once Provision finished successfully, hit the Done button to complete the process.
- mod_deflate is now enabled successfully.
Another way to enable GZIP Compression is editing website .htaccess file. We have to simply add the code in .htaccess file but make sure mod_deflate will be enabled from the server as we saw above in the article. You can find your .htaccess file on the website root directory through FTP(FileZilla).
Please ensure that this code will add below the current contents of your website .htaccess file.
How did GZIP Compression work?
When a browser (Chrome, Firefox, etc) visits a website it checks to see if the web server has GZIP enabled by seeing if the Content-encoding: gzip response header exists. If the header is detected, it serves up the compressed and smaller files. Yes, that’s the way the website loads fast.
Friends if you follow these steps, your website will definitely load fast. Please let me know through your comments if this article helps you. Keep learning.