# Gzip

> The Gzip is a lossless compression format widely used to compress HTTP responses.

## How do I enable Gzip compression for my website?

The lossless compression format based on the DEFLATE algorithm. Supported by every browser and server, it significantly reduces the size of text resources like HTML, CSS and JS.

- Topic: Compression
- Type: technique

## Example

Wrong:

```nginx
gzip on;
```

Right:

```nginx
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_min_length 1024;
gzip_vary on;
```

Nginx compresses only 'text/html' by default, so other text types must be listed; tiny files are skipped.

## Common mistakes

- Compressing files twice, so the browser shows binary garbage.

## Key points

- Text responses like HTML, CSS, JS, JSON and SVG are compressed, already compressed images are not.
- Responses include `Vary: Accept-Encoding` and the right `Content-Encoding`.
- Very small responses are skipped, since compression overhead can make them bigger.

## Interview questions

### Should I gzip images like JPEG or PNG?

No. They are already compressed, so Gzip saves almost nothing and wastes CPU. SVG is text and does benefit.

### How do I check if a response is gzipped?

Run `curl -sI -H 'Accept-Encoding: gzip' URL` and look for 'Content-Encoding: gzip', or check the response headers in DevTools.

### Is Gzip still needed if I use Brotli?

Yes, as a fallback for clients that do not send 'br' in `Accept-Encoding`, such as some tools and older clients.

## Related cards

- [Brotli](https://wonderium.dev/web/brotli.md)
- [Zstandard](https://wonderium.dev/web/zstd.md)
- [Nginx](https://wonderium.dev/web/nginx.md)
- [HTTP Header](https://wonderium.dev/web/http-header.md)
- [Minification](https://wonderium.dev/engineering/minification.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/gzip
- Last updated: 2026-11-25
