How to: Enable mod_brotli compression in WordPress
Brotli should be installed on your server. This tutorial would help you install Brotli in CentOS 7 using terminal. It’s important that you have ssh access of your server. In case you don’t have ssh access, make sure you contact your hosting provider and let him know that you need ssh for Brotli installation.
Make sure you have entered the root mode, or alternatively you can use sudo command for gaining super user permission, just as used below.
sudo yum install Brotli sudo yum install php-brotli
Run the above two commands, one by one. First command would install Brotli, provided you’ve enabled the repository. The second command would install mod_brotli for PHP.
Now, check if Brotli is working by running the following command:
The output of the above command should return as 1, this shows that Brotli is working on your server. Now, check which modules are enabled in php, run the following command:
In the output, you would see brotli along with other enabled and installed php modules. Normally, in CentOS, php modules configuration is kept in php.d directory under etc folder.
How to: Enable mod_Brotli in W3 Total Cache
We are going to use W3 Total Cache to enable Brotli compression in WordPress. Other way to do it, is to use apache configuration or .htaccess file. Since, this guide is using WordPress as target CMS; therefore, we’d use W3 Total Cache which would automatically add required .htaccess code to enable mod_brotli.
- Login to your WordPress dashboard and navigate to Performance > Browser Cache. Navigate down, and look for Enable HTTP (brotli) compresssion.
- Tick to enable Brotli compress, make sure you untick Enable HTTP (gzip) compression. This would enable Brotli compression on your WordPress website, Don’t forget to save the settings.
Gzip is mostly used by servers to compress output. Normally, 300kb file is served with 200kb size which saves bandwidth and reduced page load time. Brotli is something new, which has advanced compression algorithm. Further, in the configuration of Brotli, Compression Output Level can be set. It can range from level 1 to level 10. Greater the compression level, greater is cpu used and slower is the process. You can read more about mod_brotli at Apache server documentation. Incase you don’t understand something, make sure you ask for help in comment section.