Summary

The mod_brotli module provides
the BROTLI_COMPRESS output filter that allows output from
your server to be compressed using the brotli compression format before being sent to the client over
the network. This module uses the Brotli library found at
https://github.com/google/brotli.

If you want to restrict the compression to particular MIME types
in general, you may use the AddOutputFilterByType directive. Here is an example of
enabling compression only for the html files of the Apache
documentation:

Note

The mod_brotli module sends a Vary:
Accept-Encoding HTTP response header to alert proxies that
a cached response should be sent only to clients that send the
appropriate Accept-Encoding request header. This
prevents compressed content from being sent to a client that will
not understand it.

If you use some special exclusions dependent
on, for example, the User-Agent header, you must
manually configure an addition to the Vary header
to alert proxies of the additional restrictions. For example,
in a typical configuration where the addition of the BROTLI_COMPRESS
filter depends on the User-Agent, you should add:

Header append Vary User-Agent

If your decision about compression depends on other information
than request headers (e.g. HTTP version), you have to set the
Vary header to the value *. This prevents
compliant proxies from caching entirely.

Example

Since mod_brotli re-compresses content each
time a request is made, some performance benefit can be derived by
pre-compressing the content and telling mod_brotli to serve them
without re-compressing them. This may be accomplished using a
configuration like the following:

The BrotliAlterETag directive specifies
how the ETag hader should be altered when a response is compressed.

AddSuffix

Append the compression method onto the end of the ETag, causing
compressed and uncompressed representations to have unique ETags.
In another dynamic compression module, mod_deflate, this has been
the default since 2.4.0. This setting prevents serving "HTTP Not
Modified" (304) responses to conditional requests for compressed
content.

NoChange

Don't change the ETag on a compressed response. In another dynamic
compression module, mod_deflate, this has been the default prior to
2.4.0. This setting does not satisfy the HTTP/1.1 property that all
representations of the same resource have unique ETags.

Remove

Remove the ETag header from compressed responses. This prevents
some conditional requests from being possible, but avoids the
shortcomings of the preceding options.

The BrotliFilterNote directive
specifies that a note about compression ratios should be attached
to the request. The name of the note is the value specified for
the directive. You can use that note for statistical purposes by
adding the value to your access log.

See also

Notice:This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.