This plugin adds compression and decompression options to both origin and cache responses.
Not all clients can handle compressed content. Not all origin servers are configured to respond with compressed content when a client says it can accept it. And it’s not always necessary to make two separate requests to an origin, and track two separate cache objects, for the same content - once for a compressed version and another time for an uncompressed version.
This plugin tidies up these problems by transparently compressing or deflating
origin responses, as necessary, so that both variants of a response are stored
as alternates and the appropriate version is used for client responses,
depending on the client’s indication (via an
Accept request header) of what
it can support.
Additionally, this plugin adds configurability for what types of origin responses will receive this treatment, which will be proxied and cached with default behavior, and which may be explicitly disallowed to cache both compressed and deflated versions (because, for example, the cost of compression is known ahead of time to outweigh the space and bandwidth savings and you wish to avoid Traffic Server even testing for the possibility).
This plugin is considered stable and is included with Traffic Server by default. There are no special steps necessary for its installation.
This plugin can be used as either global plugin or remap plugin.
It can be enabled globally for Traffic Server by adding the following to your
With no further options, this will enable the following default behavior:
Enable caching of both compressed and uncompressed versions of origin responses as alternates.
Compress objects with text/* content types for every origin.
Don’t hide Accept encoding headers from origin servers (for an offloading reverse proxy).
No URLs are disallowed from compression.
Disable flush (flush compressed content to client).
Only objects greater than 1Kb will be compressed
Alternatively, a configuration may be specified (shown here using the sample configuration provided with the plugin’s source):
This can be used as remap plugin by pointing to config file in remap rule
The following sections detail the options you may specify in the plugin’s configuration file. Options may be used globally, or may be specified on a per-site basis by preceding them with a [<site>] line, where <site> is the client-facing domain for which the options should apply.
Per site configuration for remap plugin should be ignored.
When set to
true, causes Traffic Server to cache both the compressed and uncompressed
versions of the content as alternates. When set to
false, Traffic Server will cache only the compressed or decompressed variant returned
by the origin. Enabled by default.
When set to
true, causes Traffic Server to compress responses to Range Requests.
Disabled by default. Setting this to true while setting cache to false leads to delivering corrupted content.
Provides a wildcard to match against content types, determining which are to be
considered compressible. This defaults to
text/*. Takes one Content-Type
A comma separated list of response status codes for which to enable compression. Defaults to 200, 206, 304.
Minimum Content-Length value sent by the origin server to consider the response
compressible. Due to the overhead and latency of compression and decompression,
it only makes sense to compress files above a certain size threshold.
Compressing files below 150 bytes can actually make them larger. This setting
only applies if the response explicitly sends Content-Length. Regardless of
this setting, responses with
Content-Length: 0 are considered not
Provides a wildcard pattern which will be applied to request URLs. Any which
match the pattern will be considered compressible, and only deflated versions
of the objects will be cached and returned to clients. This may be useful for
objects which already have their own compression built-in, to avoid the expense
of multiple rounds of compression for trivial gains. If the regex is preceded by
! (for example
allow !*/nothere/*), it disables the plugin from those machine URLs.
When set to
true (the default) permits objects to be compressed, and when
effectively disables the plugin in the current context.
true) or disables (
false) flushing of compressed objects to
clients. This calls the compression algorithm’s mechanism (Z_SYNC_FLUSH and for gzip
and BROTLI_OPERATION_FLUSH for brotli) to send compressed data early.
When set to
true this option causes the plugin to strip the request’s
Accept-Encoding header when contacting the origin server. Setting this option to
will leave the header intact if the client provided it.
To ease the load on the origins.
For when the proxy parses responses, and the resulting compression and decompression is wasteful.
Provides the compression algorithms that are supported, a comma separate list
of values. This will allow Traffic Server to selectively support
and brotli (
br) compression. The default is
gzip. Multiple algorithms can
be selected using ‘,’ delimiter, for instance,
deflate,gzip,br. Note that this list must not contain any white-spaces!
Note that if
1, only gzip will
be considered, and if it is
2, only br or gzip will be considered.
To establish global defaults for all site requests passing through Traffic Server, while
overriding just a handful for requests to content at
might create a configuration with the following options:
Assuming the above options are in a file at
the plugin would be enabled for Traffic Server in
Alternatively, the compress plugin can be used as a remap plugin:
map http://www.example.com http://origin.example.com \ @plugin=compress.so @pparam=compress.config $ cat /etc/trafficserver/compress.config enabled true cache true compressible-content-type *xml supported-algorithms