We often have questions about testing for Gzip compression after someone tests their landing page. Gzip is most likely working. The issue is that the landing page is composed of several types of data, and .htaccess rules may have only defined certain data to be compressed. If not everything on that landing page is compressed, then it may return an erroneous result stating that compression is not enabled. We'll explain how to enable Gzip compress and how to test and confirm that it is enabled in this article.
To enable 'Gzip compression', you must enable the mod_deflate Apache module and then add .htaccess rules like these listed below:
To test whether your Apache installation had mod_deflate enabled, run the following command as root via SSH:
httpd -M | grep deflate
If this is not already enabled on your cPanel CentOS server for some reason and you are using EasyApache 4, you can enable it using the rpm command like below:
yum install ea-apache24-mod_deflate -y
Knownhost wants your sites to perform optimally, so this module is enabled on our servers by default.
You can add the .htaccess rules in cPanel via cPanel's Optimize Website interface or with the following deprecated 1)API command from the command line when logged into the server via SSH (replace 'username' with the actual cPanel user's name):
cpapi1 --user=username OptimizeWS optimizews all text/html
If you can find any updated/supported equivalent UAPI, then use that instead.
The best way to check if Gzip compression is actually working is by testing those specific resources that the .htaccess rules were written for using curl like so:
Notice the "Content-Encoding: gzip" returned, which shows that the page was gzipped.
The flags used in the curl command above are as follows:
You can also use wget to compare a compressed file download to a non-compressed file download.
First, download the compressed file:
wget --header='Accept-Encoding: gzip' http://domain.com/index.html
Next, download the non-compressed file:
Next, compare the amount of time it took overall for the compressed file and the non-compressed files to download so that you can see how much time is saved when using compression to serve files.
Additionally, you can also ask wget to save the headers:
wget --save-headers http://domain.com
You can then check the downloaded file for the headers and confirm that compression is enabled for that mime-type.
Beware, though, of the size of the file being too small for gzip! You may not see that it is gzipped if, for example, the file is smaller than 200 bytes for Litespeed servers as the default minimum file size to be gzipped by Litespeed is 200 bytes.
That's all there is to testing for compression for your site! :) Feel free to open a support ticket with your KnownHost support team if you have any questions! :)