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
- Navigate to Server Configuration → Tuning
- Find Enable Compression → set to
Yes - Set Compressible Types:
text/html, text/css, application/javascript, application/json, text/xml, application/xml, text/plain, image/svg+xml - Save and Graceful Restart
What to Compress
| Content Type | Compress? | Why |
|---|---|---|
| HTML | ✅ Yes | Large text, high compression ratio |
| CSS | ✅ Yes | Text-based, compresses well |
| JavaScript | ✅ Yes | Text-based, compresses well |
| JSON / XML | ✅ Yes | API responses, data feeds |
| SVG | ✅ Yes | Text-based image format |
| JPEG / PNG / WebP | ❌ No | Already compressed — wastes CPU |
| MP4 / Video | ❌ No | Already compressed |
| WOFF2 | ❌ No | Already 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
curland theContent-Encodingheader.
What's Next
- Continue to Brotli Compression for even better compression ratios.