Skip to content

compress for certain content-type (not simply true/false) #2124

@kachkaev

Description

@kachkaev

Do you want to request a feature or report a bug?

feature

What did you do?

I'm trying to configure a mix of microservices behind traefik, some of which are static websites served by nginx and some are Node.js APIs. I would like traefik to be a bit more selective about what it compresses, since now the only options are either all or nothing.

Nginx has got a nice option called gzip_types, which makes it possible to compress text responses while skipping jpegs, archives, videos and other binaries. The format is the following:

server {
  # ...
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp application/javascript application/json;
  # ...
}

Traefik could also use something similar in its compression middleware, i.e.:

## only certain content-types
compress = "text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp application/javascript application/json"
## or all
compress = true
## or nothing
compress = false

Being selective about what content types to compress, traefik will save CPU resources both on the server and the client while removing a need to place nginx sidecar containers next to every API endpoint that does not do compression by design (e.g. Node.js GraphQL API).

The proposed change looks backwards-compatible. WDYT?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions