Measuring Real-World Compression Savings

Learn how to measure actual compression savings using browser DevTools, curl, and monitoring tools. Verify your gzip configuration is working correctly.

Infrastructure

Detailed Explanation

Measuring Compression in Production

Setting up compression is only half the job. You need to verify it works and measure the actual savings.

Browser DevTools

The Network tab in Chrome DevTools shows both sizes:

  1. Open DevTools (F12) → Network tab
  2. Look at the Size column: shows transferred (compressed) size
  3. Hover or click to see the Resource Size (uncompressed) and Transfer Size (compressed)
  4. The difference is your compression savings

Using curl to Verify

# Check if gzip is being served
curl -H "Accept-Encoding: gzip" -sI https://example.com | grep -i content-encoding

# Get compressed size
curl -H "Accept-Encoding: gzip" -so /dev/null -w "%{size_download}" https://example.com

# Get uncompressed size
curl -so /dev/null -w "%{size_download}" https://example.com

# Detailed timing with compression
curl -H "Accept-Encoding: gzip" -w "\nTransfer: %{size_download} bytes\nTime: %{time_total}s\n" -so /dev/null https://example.com

Web Performance APIs

Measure compression savings programmatically with the Performance API:

const entries = performance.getEntriesByType('resource');
entries.forEach(entry => {
  const savings = entry.decodedBodySize - entry.transferSize;
  const ratio = (savings / entry.decodedBodySize * 100).toFixed(1);
  console.log(`${entry.name}: ${ratio}% compression savings`);
});

Lighthouse Audit

Lighthouse includes a "Enable text compression" audit that:

  • Identifies uncompressed text resources
  • Estimates potential savings
  • Flags resources over 1.4 KB that aren’t compressed

Monitoring Over Time

Track compression metrics in your monitoring dashboard:

  • Compression ratio per content type: Are all text types being compressed?
  • Compressed vs uncompressed traffic: What percentage of responses are compressed?
  • Compression CPU usage: Is compression consuming excessive server resources?
  • Cache hit rate by encoding: Are gzip and Brotli variants cached effectively?

Common Issues to Check

  1. Missing compression: Check that your server is compressing all text MIME types
  2. Inconsistent compression: Some responses compressed, others not (check Vary header)
  3. Compression on already-compressed content: Wasting CPU on images/videos
  4. Missing min-length threshold: Compressing tiny responses that don’t benefit

Use Case

Verifying compression configuration in production and debugging compression issues. Essential for performance monitoring and ensuring your CDN, load balancer, and application server are all compressing correctly.

Try It — Gzip Size Calculator

Open full tool