KNOWNHOST KNOWLEDGE BASE

Hosting Question? Find the Solution - Browse our Guides, Articles, and How-To's

How to Check Whether Gzip Compression is Working?

Category: Guides
Tags: # # # #

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 comprises 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, 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.


How To Enable Gzip Compression (mod_deflate)

To enable ‘Gzip compression’, you must enable the mod_deflate Apache module and then add .htaccess rules like these listed below,

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

To test whether your Apache installation had mod_deflate enabled, run the following command as root via SSH,

httpd -M | grep deflate
[root@host ~]#   httpd -M | grep deflate
 deflate_module (shared)

Notice that the .htaccess rules will Compress HTML, CSS, JavaScript, Text, XML and fonts. Any other content won’t be compressed. If your site contains a lot of different types of content, not all contents may be compressed. This will cause the landing page to show as if it were not compressed either. This explains why testing just the site’s landing page via online testing tools like Webpagespeedtest and Pingdom and the like may erroneously state that the site lacks gzip compression.


Checking Gzip Compression With Curl

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,

wget http://domain.com/index.html

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.


Conclusion

Now that we’ve gone over how to check whether Gzip compression is working or not. We have covered the two methods to check to check Gzip compression on the server (wget & curl). Knownhost wants your sites to perform optimally, so this module is enabled on our servers by default.

KnownHost offers 365 days a year, 24 hours a day, all 7 days of the week best in class technical support. A dedicated team ready to help you with requests should you need our assistance. You’re not using KnownHost for the best webhosting experience? Well, why not? Check with our Sales team to see what can KnownHost do for you in improving your web hosting experience.