docs/content/reference/routing-configuration/http/middlewares/compress.md
The compress middleware compresses response. It supports Gzip, Brotli and Zstandard compression
# Enable compression
http:
middlewares:
test-compress:
compress: {}
# Enable compression
[http.middlewares]
[http.middlewares.test-compress.compress]
# Enable compression
labels:
- "traefik.http.middlewares.test-compress.compress=true"
// Enable compression
{
//...
"Tags": [
"traefik.http.middlewares.test-compress.compress=true"
]
}
# Enable compression
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-compress
spec:
compress: {}
| Field | Description | Default | Required |
|---|---|---|---|
<a id="opt-excludedContentTypes" href="#opt-excludedContentTypes" title="#opt-excludedContentTypes">excludedContentTypes</a> | List of content types to compare the Content-Type header of the incoming requests and responses before compressing. | ||
The responses with content types defined in excludedContentTypes are not compressed. | |||
| Content types are compared in a case-insensitive, whitespace-ignored manner. | |||
The excludedContentTypes and includedContentTypes options are mutually exclusive. | "" | No | |
<a id="opt-defaultEncoding" href="#opt-defaultEncoding" title="#opt-defaultEncoding">defaultEncoding</a> | specifies the default encoding if the Accept-Encoding header is not in the request or contains a wildcard (*). | "" | No |
<a id="opt-encodings" href="#opt-encodings" title="#opt-encodings">encodings</a> | Specifies the list of supported compression encodings. At least one encoding value must be specified, and valid entries are zstd (Zstandard), br (Brotli), and gzip (Gzip). The order of the list also sets the priority, the top entry has the highest priority. | gzip, br, zstd | No |
<a id="opt-includedContentTypes" href="#opt-includedContentTypes" title="#opt-includedContentTypes">includedContentTypes</a> | List of content types to compare the Content-Type header of the responses before compressing. | ||
The responses with content types defined in includedContentTypes are compressed. | |||
| Content types are compared in a case-insensitive, whitespace-ignored manner. | |||
The excludedContentTypes and includedContentTypes options are mutually exclusive. | "" | No | |
<a id="opt-minResponseBodyBytes" href="#opt-minResponseBodyBytes" title="#opt-minResponseBodyBytes">minResponseBodyBytes</a> | `Minimum amount of bytes a response body must have to be compressed. | ||
| Responses smaller than the specified values will not be compressed. | 1024 | No |
The activation of compression, and the compression method choice rely (among other things) on the request's Accept-Encoding header.
Responses are compressed when the following criteria are all met:
Accept-Encoding request header contains gzip, *, and/or br, and/or zstd with or without quality values.
If the Accept-Encoding request header is absent, the response won't be encoded.
If it is present, but its value is the empty string, then compression is turned off.Content-Encoding response header is not already set.Content-Type header is not one among the excludedContentTypes options, or is one among the includedContentTypes options.minResponseBodyBytes) (default is 1024).If the Content-Type header is not defined, or empty, the compress middleware will automatically detect a content type.
It will also set the Content-Type header according to the detected MIME type.
Note that application/grpc is never compressed.