Skip to main content

Gzip Compression

Learning Focus

By the end of this lesson you will know how to enable gzip compression in OpenLiteSpeed, which content types to compress, and how to verify it is working.

What Gzip Does

Gzip compresses text-based responses (HTML, CSS, JavaScript, JSON) before sending them to the browser. The browser decompresses them transparently. This reduces transfer size by 60-80% for text content.

Enabling Gzip in WebAdmin

  1. Navigate to Server ConfigurationTuning
  2. Find Enable Compression → set to Yes
  3. Set Compressible Types: text/html, text/css, application/javascript, application/json, text/xml, application/xml, text/plain, image/svg+xml
  4. Save and Graceful Restart

What to Compress

Content TypeCompress?Why
HTML✅ YesLarge text, high compression ratio
CSS✅ YesText-based, compresses well
JavaScript✅ YesText-based, compresses well
JSON / XML✅ YesAPI responses, data feeds
SVG✅ YesText-based image format
JPEG / PNG / WebP❌ NoAlready compressed — wastes CPU
MP4 / Video❌ NoAlready compressed
WOFF2❌ NoAlready compressed

Verifying Compression

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

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

Do not enable compression for already-compressed formats like JPEG, PNG, MP4, or WOFF2. It wastes CPU without reducing size.

Key Takeaways

  • Enable gzip for all text-based content types — HTML, CSS, JS, JSON, XML, SVG.
  • Skip already-compressed formats like images, video, and modern fonts.
  • Verify with curl and the Content-Encoding header.

What's Next