Help Docs Server Administration Linux Server Administration Apache Web Server Installing mod_brotli

Installing mod_brotli

Install & configure `mod_brotli` on Apache. Learn to enable Brotli compression, verify it, and manage its preference over Gzip for faster sites.

Improving your website’s loading speed is essential for a good user experience and better search engine rankings. One effective way to achieve this is through compression, which reduces the size of files sent from your server to visitors’ browsers. While Gzip compression is widely used, Brotli is a newer algorithm specifically designed for web content compression. mod_brotli enables your Apache web server to utilize this technology.

Installation

This section covers the installation of mod_brotli.

For systems using EasyApache 4, you can install mod_brotli using your package manager.

yum install ea-apache24-mod_brotli ea-brotli

For those using cPanel you can get the instructions for it here.

https://docs.cpanel.net/ea4/apache/apache-modules/apache-module-brotli

Is it working?

To check if mod_brotli is working and the server is delivering content compressed with Brotli, you can use the curl command, specifying that you accept Brotli encoding.

curl -H "Accept-Encoding: br" -I http://www.domain.com/

If it’s working correctly, you should see a header in the output indicating Content-Encoding: br.

Content-Encoding: br

Potential conflicts with mod_deflate

You might wonder if mod_brotli conflicts with Mod_Deflate (which provides Gzip compression). According to the sources, no, this will not conflict. mod_brotli simply provides the server with another method of compression to offer to clients.

Server preference: Brotli or Gzip?

When both mod_brotli and Mod_Deflate are configured, how does the server decide which compression method to use? You can test which one the server is preferring by using curl and specifying that you accept both gzip and br encoding.

curl -H "Accept-Encoding: gzip br" -I http://www.domain.com/

The server will respond with the header indicating which encoding it chose. For example, if it prefers Gzip, you would see:

Content-Encoding: gzip

Changing server preference

The server’s preference is determined by the order of the configuration entries in the Apache configuration files. If the mod_deflate entries appear above the mod_brotli entries in the configuration, Gzip will be preferred. Conversely, if mod_brotli entries are above mod_deflate, Brotli will be preferred. To change the server’s preference, you simply need to change the order of these configurations.

Browser compatibility

Most modern browsers support Brotli compression. A list of compatible browsers can often be found online . If you require support for legacy browsers, it is important to ensure Mod_Deflate is also configured, keeping in mind the preference setting mentioned above. This allows the server to fall back to Gzip for browsers that do not support Brotli.

Was this article helpful?