Enable Brotli on Apache!

Since version 2.4.26, Apache already comes with a built-in Brotli module. In case you have an older version, please make sure to upgrade your Apache server before applying further instructions! Also, in case you don't have HTTPS enabled on your server by now, you should do it soon (read: now). Getting an HTTPS certificate with services like Let's Encrypt is easy and free nowadays.

With HTTPS set up, you can now enable the Apache module with the command a2enmod brotli if it is not already enabled out of the box. Now, open your VirtualHost or server config and add the output filter for Brotli: AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript. This will compress most text-based files like HTML, Javascript, CSS, XML and plain text files.
PS: Do not compress images (neither with GZIP nor Brotli) as they are already compressed!
If you want to change the compression level, you can add BrotliCompressionQuality LEVEL to your VirtualHost oder server config. The default level is 5 but we would suggest using 4 as it is both: faster and more efficient than GZIP.

Be aware that Apache does not support static compression (like you can achieve with webpack, express or other technologies). All compression is done on the fly while requesting the file.