Configure > Compress Directives
The compress handler performs on-the-fly compression - it compresses the contents of an HTTP response as it is being sent, if the client indicates itself to be capable of decompressing the response transparently with the use of Accept-Encoding header, and if the response is deemed compressible according to the following rules.
If x-compress-hint response header does not exist or the value is auto, then whether if the response is considered compressible depends on the is_compressible attribute assigned to the content type (see file.mime.addtypes).
If x-compress-hint response header exists and the value is on, the response is always considered to be compressible.
If the value of the response header is set to off, then the response never gets compressed.
The following are the configuration directives recognized by the handler.
"compress"
- Description:
-
Enables on-the-fly compression of HTTP response.
If the argument is
ON, gzip is enabled for compression. Brotli and zstd will also be enabled when the server was built with their support. If the argument is a sequence, the elements are the list of compression algorithms to be enabled.The default qualities specified for each compression method are: 1 for gzip, 1 for brotli, and 3 for zstd. To override the qualities, use a mapping with each key-value pair specifying the compression algorithm and the quality (gzip: 1-9, br: 0-11, zstd: 1-22).
When multiple algorithms are enabled and the client supports more than one, H2O prefers brotli, then zstd, then gzip.
If the argument is
OFF, on-the-fly compression is disabled.Example. Enabling on-the-fly compression# enable all algorithms compress: ON # enable by name compress: [ gzip, br, zstd ] # enable gzip only compress: [ gzip ] # tune zstd quality compress: zstd: 7 - Level:
- global, host, path, extension
- Default:
compress: OFF
- See also:
file.send-compressed,file.mime.addtypes
"compress-minimum-size"
- Description:
-
Defines the minimum size a files needs to have in order for H2O to compress the request.
- Level:
- global, host, path, extension
- Default:
compress-minimum-size: 100