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 all of the following conditions are met:
- client indicates itself to be capable of decompressing the response transparently with the use of
Accept-Encoding
header - the response is deemed compressible (by checking the content-type, see
file.mime.addtypes
)
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
, both brotli and gzip compression are enabled. If the argument isOFF
, on-the-fly compression is disabled. If the argument is a sequence, the elements are the list of compression algorithms to be enabled. If the argument is a mapping, each key specifies the compression algorithm to be enabled, and the values specify the quality of the algorithms.When both brotli and gzip are enabled and if the client supports both, H2O is hard-coded to prefer brotli.
Example. Enabling on-the-fly compression# enable all algorithms compress: ON # enable by name compress: [ gzip, brotli ] # enable gzip only compress: [ gzip ]
- Level:
- global, host, path, extension
- Default:
compress: OFF
- See also:
file.send-compressed
,file.mime.addtypes