Gzip is a lossless compression format based on the DEFLATE algorithm. A web server applies it to text responses on the fly, and the browser decompresses them, so fewer bytes cross the network.
Why it matters
Text compresses well. HTML, CSS, JavaScript, JSON and SVG commonly shrink by 60 to 80 percent, which cuts transfer time and bandwidth cost, especially on slow mobile links. Virtually every browser and client supports it, so it is the safe baseline when Brotli is not available.
Negotiation is automatic. The browser sends Accept-Encoding: gzip, br, and the server replies with Content-Encoding: gzip if it compressed the body.
Example
GET /app.js HTTP/1.1
Accept-Encoding: gzip, deflate, br
HTTP/1.1 200 OK
Content-Type: application/javascript
Content-Encoding: gzip
Vary: Accept-Encoding
In nginx, gzip on; plus gzip_types text/css application/javascript application/json; enables it for those types.
Common mistakes
- Compressing images, video or zip files. JPEG, PNG, WebP and MP4 are already compressed, so gzip adds CPU cost for little or no gain.
- Forgetting the
Vary: Accept-Encodingheader, which can make caches serve compressed data to clients that cannot read it. - Setting level 9 for on-the-fly compression; mid levels are usually the better trade-off.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.