← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Gzip / Brotli Compression

Performance Beginner
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints list Lighthouse, curl, and WebPageTest — these are not default linter tools but specialist external auditing tools that must be deliberately run. Missing compression is silent in normal development; it only surfaces when someone explicitly checks response headers or runs a performance audit. Slightly better than d9 because these tools do catch it reliably once run.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is a small Nginx config addition (gzip on; gzip_types ...; gzip_min_length ...) — a few lines in one config file. However, if PHP ob_gzhandler() must be removed and server config updated, it is slightly more than a one-line patch, placing it firmly at e3 rather than e1.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is web only, and the configuration lives primarily in the server layer (Nginx/Apache config or CDN settings). Once correctly configured, it imposes minimal ongoing maintenance burden on developers — it does not shape future code decisions across the codebase.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states the canonical wrong belief: developers assume gzip should be applied to all response types, but applying it to already-compressed formats (JPEG, PNG, ZIP, video) wastes CPU and can increase response size. This is a well-documented gotcha that many developers learn through experience, aligning with t5.

About DEBT scoring →

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;

Added 15 Mar 2026
Edited 22 Mar 2026
Views 72
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 6 pings S 3 pings M 1 ping T 2 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Google 15 Scrapy 10 Amazonbot 8 Perplexity 7 SEMrush 5 ChatGPT 4 Ahrefs 4 Unknown AI 2 Claude 2 Meta AI 1 Bing 1 Sogou 1 Majestic 1 PetalBot 1
crawler 56 crawler_json 6
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


✓ schema.org compliant