Gzip
The most widely supported HTTP compression algorithm. Uses the deflate algorithm. Compresses text-based content by 60-80%. Supported everywhere, but Brotli is now preferred for better ratios.
Full Explanation
Gzip has been the default web compression since the late '90s. It's fast, well-understood, and supported by literally everything—every browser, every server, every CDN, every proxy. When in doubt, gzip works.
Compression levels go from 1 (fast, less compression) to 9 (slow, more compression). For dynamic content served by CDN edges, level 4-6 is the sweet spot—good compression without burning too much CPU. For static assets, pre-compress at level 9 and serve the files directly.
Gzip is being overtaken by Brotli (15-25% better ratios) and increasingly by Zstandard (similar ratios to Brotli, faster compression). But gzip remains the universal fallback. A solid setup: serve Brotli to clients that support it, fall back to gzip for the rest.
Try the interactive Compression Comparison animation in the course to compare gzip against Brotli and zstd on real content.
Interactive Animation
Examples
# Nginx gzip configuration
gzip on;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
text/html
text/css
text/javascript
application/javascript
application/json
application/xml
image/svg+xml;
gzip_vary on;
# Pre-compress static files (build step)
$ gzip -k -9 bundle.js # Creates bundle.js.gz
# Nginx: serve pre-compressed files
gzip_static on; # Serves .gz file if it exists
# Test gzip support
$ curl -H 'Accept-Encoding: gzip' -sI https://example.com/ | grep content-encoding
Content-Encoding: gzip
Frequently Asked Questions
The most widely supported HTTP compression algorithm. Uses the deflate algorithm. Compresses text-based content by 60-80%. Supported everywhere, but Brotli is now preferred for better ratios.
# Nginx gzip configuration
gzip on;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
text/html
text/css
text/javascript
application/javascript
application/json
application/xml
image/svg+xml;
gzip_vary on;
# Pre-compress static files (build step)
$ gzip -k -9 bundle.js # Creates bundle.js.gz
# Nginx: serve pre-compressed files
gzip_static on; # Serves .gz file if it exists
# Test gzip support
$ curl -H 'Accept-Encoding: gzip' -sI https://example.com/ | grep content-encoding
Content-Encoding: gzip
Related CDN concepts include:
- Content-Encoding — An HTTP response header indicating the compression algorithm applied to the response body. Common values: …
- Vary Header — A response header that tells caches which request headers should be included in the cache …
- Brotli — A compression algorithm developed by Google that typically achieves 15-25% better compression than gzip for …
- Compression — Reducing the size of HTTP response bodies before transmission. Common algorithms: gzip, Brotli, and zstd. …