Gzip / Brotli Compression
debt(d7/e3/b3/t5)
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.
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.
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.
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.
Also Known As
TL;DR
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
Why It Matters
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
# 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;
; 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;