TL;DR
Brotli compression makes your website load faster by reducing the size of files sent to visitors using HTTPS. This guide shows you how to enable it on your web server (Apache or Nginx).
What is Brotli?
Brotli is a modern compression algorithm that generally compresses data better than gzip, resulting in smaller file sizes and faster loading times for your website. It’s supported by most modern browsers.
Checking if Your Server Supports Brotli
Before you start, make sure your server has the necessary modules installed. Most recent versions of Apache and Nginx do.
Enabling Brotli on Apache
- Install the
mod_brotlimodule: The exact command depends on your operating system. For Debian/Ubuntu:sudo apt update sudo apt install libapache2-mod-brotliFor CentOS/RHEL:
sudo yum install mod_brotli - Enable the module:
sudo a2enmod brotli - Configure Brotli in your Apache configuration file (usually
.htaccessor within your virtual host): Add these lines:<IfModule mod_brotli.c> BrotliCompression on BrotliCompressionLevel 6 # Adjust level between 1-11 (higher = more compression, slower) AddType text/html brotli .html AddType text/css brotli .css AddType application/javascript brotli .js </IfModule>Important: If using
.htaccess, ensureAllowOverride Allis set in your virtual host configuration. - Restart Apache:
sudo systemctl restart apache2
Enabling Brotli on Nginx
- Check if the
ngx_http_brotli_moduleis installed: Run:nginx -V 2>&1 | grep --color=auto brotliIf it’s not listed, you need to recompile Nginx with Brotli support. This process varies depending on how you installed Nginx (package manager or source).
- Configure Brotli in your Nginx configuration file (usually
nginx.conf): Add these lines within thehttpblock:brotli_types text/html text/css application/javascript image/svg+xml; brotli on; brotli_compression_level 6; # Adjust level between 1-11 (higher = more compression, slower) brotli_buffers 4 8k; - Restart Nginx:
sudo systemctl restart nginx
Testing Brotli Compression
Use a website speed testing tool like PageSpeed Insights or GTmetrix to verify that Brotli compression is enabled for your site. Look for ‘Brotli’ in the results.
Troubleshooting
- Browser Support: Ensure visitors are using a modern browser that supports Brotli.
- Configuration Errors: Double-check your configuration files for typos or incorrect settings.
- Server Logs: Examine your server’s error logs for any clues about why Brotli isn’t working.

