Gzip / Brotli Compression
Also Known As
HTTP compression
gzip encoding
deflate compression
brotli
TL;DR
Compressing HTTP responses server-side reduces transfer size significantly, especially for text-based assets.
Explanation
Gzip and the newer Brotli algorithm compress HTTP response bodies before transmission, reducing bandwidth and improving load times — HTML, CSS, and JS typically compress by 60–90%. In PHP applications, compression can be applied by the web server (Nginx gzip, Apache mod_deflate) rather than in PHP itself (avoid ob_gzhandler as it conflicts with streaming and partial content). Enable compression for text-based MIME types (text/html, text/css, application/json), exclude already-compressed binary formats (images, videos), and set Vary: Accept-Encoding when using compression.
Common Misconception
✗ Gzip should be applied to all response types for maximum performance. Gzip is effective for text-based content (HTML, CSS, JS, JSON) but counterproductive for already-compressed formats like JPEG, PNG, ZIP, and video — compressing them wastes CPU and often increases response size.
Why It Matters
Gzip compresses HTTP responses by 60-90% for text content — reducing bandwidth costs and improving page load times with minimal CPU overhead.
Common Mistakes
- Not enabling gzip for text responses (HTML, CSS, JS, JSON, XML) — the most impactful compression targets.
- Enabling gzip for already-compressed formats (images, video, zipped files) — wastes CPU with no size benefit.
- Using PHP ob_gzhandler() instead of server-level compression — server-level is more efficient.
- Not checking that Content-Encoding: gzip is actually in responses — easy to misconfigure and never notice.
Code Examples
✗ Vulnerable
# nginx — gzip not configured:
server {
# gzip off; (default)
# All responses sent uncompressed — HTML/CSS/JS 5-10x larger than needed
}
# Correct:
gzip on;
gzip_types text/html text/css application/javascript application/json;
gzip_min_length 1000;
✓ Fixed
; php.ini — enable zlib output compression
zlib.output_compression = On
zlib.output_compression_level = 6 ; 1-9, 6 is good balance
; Or in nginx (preferred — offloads from PHP)
gzip on;
gzip_vary on;
gzip_min_length 1024; ; don't compress tiny responses
gzip_types text/plain text/css application/json application/javascript
text/xml application/xml image/svg+xml;
gzip_comp_level 6;
; Brotli (better compression, HTTPS only)
brotli on;
brotli_types text/plain text/css application/json application/javascript;
brotli_comp_level 6;
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
35
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Google 12
Perplexity 7
Amazonbot 6
Unknown AI 2
Ahrefs 2
SEMrush 2
ChatGPT 1
How they use it
crawler 29
crawler_json 3
Related categories
⚡
DEV INTEL
Tools & Severity
🟠 High
⚙ Fix effort: Low
⚡ Quick Fix
Enable gzip in Nginx: gzip on; gzip_types text/html text/css application/javascript application/json; gzip_min_length 1000 — reduces transfer size 60-80% for text assets
📦 Applies To
any
web
🔗 Prerequisites
🔍 Detection Hints
Nginx config without gzip on; PHP serving uncompressed CSS/JS; no Content-Encoding: gzip in response headers
Auto-detectable:
✓ Yes
lighthouse
curl
webpagetest
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Low
✓ Auto-fixable
Fix: Low
Context: File