ngx_brotli

Brotli compression for responses and static assets

compiled inBSD-2-Clausesource

Overview

ngx_brotli adds Brotli compression to nginx. Brotli is a compression format developed at Google that typically produces smaller output than gzip at comparable speed, and every modern browser advertises support for it in the Accept-Encoding header.

The project ships two modules. The filter module compresses responses on the fly, and the static module serves pre-compressed .br files from disk so no CPU is spent at request time.

Google maintains the module. It is one of the most widely deployed third-party nginx modules and is compiled into most distribution builds.

Key directives

brotliEnables on-the-fly Brotli compression of responses; off by default.
brotli_comp_levelSets the compression quality from 0 to 11, default 6.
brotli_typesLimits compression to the listed MIME types, default text/html.
brotli_min_lengthSkips responses shorter than the given byte length, default 20.
brotli_staticServes a pre-compressed .br file next to the original when the client accepts Brotli.
brotli_windowSets the sliding window size used during compression, default 512k.

Example

nginx.conf
brotli on; brotli_comp_level 6; brotli_types text/plain text/css application/javascript application/json image/svg+xml; # serve pre-compressed .br files when they exist on disk brotli_static on;

Availability

Compiled into every n.wtf nginx binary. Install nginx-extras and the directives above work out of the box, no load_module line needed.