mirror of
				https://github.com/traefik/traefik.git
				synced 2025-10-31 16:31:16 +01:00 
			
		
		
		
	
		
			
				
	
	
	
		
			4.6 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			4.6 KiB
		
	
	
	
	
	
	
	
title, description
| title | description | 
|---|---|
| Traefik Compress Documentation | Traefik Proxy's HTTP middleware lets you compress responses before sending them to the client. Read the technical documentation. | 
The compress middleware compresses response. It supports Gzip, Brotli and Zstandard compression
Configuration Examples
# 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: {}
Configuration Options
| Field | Description | Default | Required | 
|---|---|---|---|
| excludedContentTypes | List of content types to compare the Content-Typeheader of the incoming requests and responses before compressing.The responses with content types defined in excludedContentTypesare not compressed.Content types are compared in a case-insensitive, whitespace-ignored manner. The excludedContentTypesandincludedContentTypesoptions are mutually exclusive. | "" | No | 
| defaultEncoding | specifies the default encoding if the Accept-Encodingheader is not in the request or contains a wildcard (*). | "" | No | 
| encodings | Specifies the list of supported compression encodings. At least one encoding value must be specified, and valid entries are zstd(Zstandard),br(Brotli), andgzip(Gzip). The order of the list also sets the priority, the top entry has the highest priority. | zstd, br, gzip | No | 
| includedContentTypes | List of content types to compare the Content-Typeheader of the responses before compressing.The responses with content types defined in includedContentTypesare compressed.Content types are compared in a case-insensitive, whitespace-ignored manner. The excludedContentTypesandincludedContentTypesoptions are mutually exclusive. | "" | No | 
| minResponseBodyBytes | `Minimum amount of bytes a response body must have to be compressed. Responses smaller than the specified values will not be compressed. | 1024 | No | 
Compression activation
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:
- The Accept-Encodingrequest header containsgzip,*, and/orbr, and/orzstdwith or without quality values. If theAccept-Encodingrequest 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.
- The response is not already compressed, that is the Content-Encodingresponse header is not already set.
- The responseContent-Typeheader is not one among theexcludedContentTypesoptions, or is one among theincludedContentTypesoptions.
- The response body is larger than the configured minimum amount of bytes(option minResponseBodyBytes) (default is1024).
Empty Content-Type Header
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.
GRPC application
Note that application/grpc is never compressed.