gzip enables gzip compression if the client supports it. By default, responses are not gzipped. If enabled, the default settings will ensure that images, videos, and archives (already compressed) are not gzipped.
Note that, even without the gzip directive, Caddy will serve .gz (gzip) or .br (brotli) compressed files if they already exist on disk and the client supports that encoding.
The plain gzip config is good enough for most things, but you can gain more control if needed:
- extensions... is a space-separated list of file extensions to compress. Supports wildcard
*to match all extensions.
- paths is a space-separated list of paths in which not to compress.
- compression_level is a number from 1 (best speed) to 9 (best compression). Default is 6.
- min_bytes is the minimum number of bytes in a response needed before compression will happen. Default is no minimum length.
Enable gzip compression:
Enable very fast but minimal compression except in the /images and /videos folders (note, however, that images and videos will not be gzipped anyway):
not /images /videos