Add Brotli compression support to Apache for static assets and pages
The Apache web server doesn’t yet support stream compression using Brotli, but it’s easy to add support for static pages and assets such as CSS and Javascript files that you precompress. Browser support for Brotli is coming in Firefox 44 and in Chrome, and it provides about 15% savings versus precompressing with gzip/deflate.
First, download and build Brotli if it’s not already installed on your system. You’ll need to run make in the “dec”, “enc” and “tools” directories to build the bro executable. A quick note here, if you’re using an older version of GCC you might get an error message because your g++ doesn’t support the -std=c++11 flag. I ran into this on an older Debian server (GCC 4.6.3 from 2011), changed -std=c++11 to -std=c++0x in the CXXFLAGS line of shared.mk, and the build completed normally.
Compress and configure
Next, compress your files. If you already have static files compressed with the .gz extension, here’s a one-liner to recompress them all using bro: