How to Verify Apache Gzip/Deflate Compression is Working: 5 Testing Methods


2 views

The easiest way to check is through Chrome/Firefox DevTools:

1. Open Developer Tools (F12)
2. Go to Network tab
3. Reload the page
4. Click the specific request
5. Check "Content-Encoding: gzip" in Response Headers

For server-side verification without a browser:

curl -I -H "Accept-Encoding: gzip,deflate" http://yoursite.com

Look for these headers in response:

Content-Encoding: gzip
Vary: Accept-Encoding

Several web services can test compression:

  • https://checkgzipcompression.com
  • https://www.giftofspeed.com/gzip-test/

Add this to Apache config for debug logging:

<IfModule mod_deflate.c>
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/deflate_log deflate
</IfModule>

Create a test script to verify compression:

<?php
ob_start("ob_gzhandler");
echo str_repeat("This content should be compressed ", 1000);
?>

Ensure your Apache config includes:

# Proper MIME type handling
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript

# Required for proper caching
Header append Vary User-Agent env=!dont-vary
Header append Vary Accept-Encoding

The easiest way to check if Apache compression is working is through your browser's developer tools:

1. Open Chrome DevTools (F12 or Ctrl+Shift+I)
2. Go to the Network tab
3. Reload your page
4. Click on the document request (usually the first entry)
5. Check the "Response Headers" section

You should see either of these headers indicating compression is working:

Content-Encoding: gzip
Content-Encoding: deflate

For command-line verification, use curl with the following flags:

curl -I -H "Accept-Encoding: gzip,deflate" http://yourdomain.com

This should return headers including:

HTTP/1.1 200 OK
Content-Encoding: gzip
Vary: Accept-Encoding

For more detailed testing, you might want to add specific logging to your Apache config:

<IfModule mod_deflate.c>
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/deflate_log deflate
</IfModule>

This will create a log file showing compression ratios for each request.

If compression isn't working, check these potential problems:

1. Verify mod_deflate is loaded: apachectl -M | grep deflate
2. Check for conflicting directives in .htaccess files
3. Ensure no SetEnvIfNoCase rules are excluding your content
4. Test with different content types (some may be excluded by default)

Here's a comprehensive mod_deflate configuration example:

<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

    # Browser bugs workarounds
    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>