Compress

Compress Responses before Sending them to the Client

Compress

The Compress middleware uses gzip compression.

Configuration Examples

Docker

  1. # Enable gzip compression
  2. labels:
  3. - "traefik.http.middlewares.test-compress.compress=true"

Kubernetes

  1. # Enable gzip compression
  2. apiVersion: traefik.containo.us/v1alpha1
  3. kind: Middleware
  4. metadata:
  5. name: test-compress
  6. spec:
  7. compress: {}

Consul Catalog

  1. # Enable gzip compression
  2. - "traefik.http.middlewares.test-compress.compress=true"

Marathon

  1. "labels": {
  2. "traefik.http.middlewares.test-compress.compress": "true"
  3. }

Rancher

  1. # Enable gzip compression
  2. labels:
  3. - "traefik.http.middlewares.test-compress.compress=true"

File (YAML)

  1. # Enable gzip compression
  2. http:
  3. middlewares:
  4. test-compress:
  5. compress: {}

File (TOML)

  1. # Enable gzip compression
  2. [http.middlewares]
  3. [http.middlewares.test-compress.compress]

Info

Responses are compressed when the following criteria are all met:

  • The response body is larger than 1400 bytes.
  • The Accept-Encoding request header contains gzip.
  • The response is not already compressed, i.e. the Content-Encoding response header is not already set.

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.

Configuration Options

excludedContentTypes

excludedContentTypes specifies 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.

Docker

  1. labels:
  2. - "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"

Kubernetes

  1. apiVersion: traefik.containo.us/v1alpha1
  2. kind: Middleware
  3. metadata:
  4. name: test-compress
  5. spec:
  6. compress:
  7. excludedContentTypes:
  8. - text/event-stream

Consul Catalog

  1. - "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"

Marathon

  1. "labels": {
  2. "traefik.http.middlewares.test-compress.compress.excludedcontenttypes": "text/event-stream"
  3. }

Rancher

  1. labels:
  2. - "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"

File (YAML)

  1. http:
  2. middlewares:
  3. test-compress:
  4. compress:
  5. excludedContentTypes:
  6. - text/event-stream

File (TOML)

  1. [http.middlewares]
  2. [http.middlewares.test-compress.compress]
  3. excludedContentTypes = ["text/event-stream"]