Using Brotli to pre-compress content
Hello,
Been using brotli for a while now, its very good in general. However I have failed to get the pre-compressed part working. It would appear that brotli is compressing on the fly each time rather than saving the files and serving those.
I have set up the config so that it is meant to serve pre-compressed it just doesn't seem to work. Would love some help.
/etc/apache2/conf.d/brotli.conf
the pre-compression stuff has been added to -> post_virtualhost_global.conf
According to official docs I should have pre-compressed files being served. But if I disable brotli or remove the conf file (while leaving include in lace) comrpessed files are not served. Also when trying to search for the files I do not find anything with .br for any sites Appreciate any help given
# Compress only a few types
# https://httpd.apache.org/docs/trunk/mod/mod_brotli.html
AddOutputFilterByType BROTLI_COMPRESS text/plain text/css text/html text/svg application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/x-font-ttf application/vnd.ms-fontobject image/x-icon
SetOutputFilter BROTLI_COMPRESS
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|swf|woff|woff2)$ no-brotli
# logging
BrotliFilterNote Input instream
BrotliFilterNote Output outstream
BrotliFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' brotli
CustomLog "logs/brotli_log" brotli
the pre-compression stuff has been added to -> post_virtualhost_global.conf
# Serve brotli compressed CSS and JS files if they exist
# and the client accepts brotli.
RewriteCond "%{HTTP:Accept-encoding}" "br"
RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
RewriteRule "^(.*)\.(js|css)" "$1\.$2\.br" [QSA]
# Serve correct content types, and prevent double compression.
RewriteRule "\.css\.br$" "-" [T=text/css,E=no-brotli:1]
RewriteRule "\.js\.br$" "-" [T=text/javascript,E=no-brotli:1]
# Serve correct encoding type.
Header append Content-Encoding br
# Force proxies to cache brotli &
# non-brotli css/js files separately.
Header append Vary Accept-Encoding
According to official docs I should have pre-compressed files being served. But if I disable brotli or remove the conf file (while leaving include in lace) comrpessed files are not served. Also when trying to search for the files I do not find anything with .br for any sites Appreciate any help given
Please sign in to leave a comment.
Comments
0 comments