Compress

Compressing the Response before Sending it to the Client

Compress

The Compress middleware enables the gzip compression.

Configuration Examples

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

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

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

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

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

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

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

Info

Responses are compressed when:

  • 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.

Configuration Options

excludedContentTypes

excludedContentTypes specifies a list of content types to compare the Content-Type header of the incoming requests to before compressing.

The requests with content types defined in excludedContentTypes are not compressed.

Content types are compared in a case-insensitive, whitespace-ignored manner.

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

  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

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

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

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

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

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