This package implements a brotli encoder for Caddy.
Requires Caddy 2+.
Uses the pure Go Brotli implementation https://github.com/andybalholm/brotli
This implementation is not high performance on better compression levels (5-12), so it is not recommended to use this encoding as primary compression algorithm. Use zstd with a gzip fallback instead.
Zstd (klauspost/compress) at level better
is 3x faster than Brotli at level 4 (similar compression ratios
on Isaac.Newton-Opticks.txt
test data).
xcaddy build --with github.com/ueffel/caddy-brotli
There will be the new encoding br
available within the
encode directive
encode [<matcher>] <formats...> {
br [<level>]
}
level
controls the compression level (ranges from 0 to 11), default is 4.
Example usages could look like this:
encode br
encode {
br 4
}
or together with gzip
encode gzip br
encode {
gzip 5
br 4
}
Update 2: From Caddy v2.4.0 onwards preferred order is implied by definition order.
Update: Since Caddy v2.4.0-beta.2 the preferred order of encodings can be set via prefer
setting.
There is currently no way to set a prefered order of content-encodings via caddy's configuration. The content-encoding is determined by the clients preference. In most cases that means a response is encoded with the first accepted encoding in the
Accept-Encoding
header of the request that the caddy also supports.Example:
Caddyfile
encode gzip br
Request:
[...] Accept-Encoding: deflate, gzip, br [...]
Response will be:
[...] Content-Encoding: gzip [...]
Request: (different order of encodings)
[...] Accept-Encoding: deflate, br, gzip [...]
Response will be:
[...] Content-Encoding: br [...]