Gzip is a lossless data compression algorithm (GNU zip) that web servers use to compress response bodies before transmitting them over the network. The browser decompresses the data before rendering it. For text-based files — HTML, CSS, JavaScript, JSON, XML — Gzip typically reduces file size by 60–90%.
How Gzip Works in HTTP
- The browser sends a request with the header:
Accept-Encoding: gzip, deflate, br - The server compresses the response and replies with:
Content-Encoding: gzip - The browser decompresses the response and renders it normally.
Gzip vs Brotli
- Gzip — Universal support, very fast compression/decompression. The standard choice.
- Brotli — Developed by Google. Compresses 15–25% better than Gzip for web assets. Supported by all modern browsers. Use Brotli when available, Gzip as fallback.
Enabling Gzip on Common Servers
- Nginx —
gzip on;in nginx.conf. - Apache — Enable
mod_deflate. - IIS — Enable Dynamic / Static Compression in site settings.
- ASP.NET Core — Add
app.UseResponseCompression().