]> git.openstreetmap.org Git - chef.git/commitdiff
Enable brotli compression of matomo script
authorTom Hughes <tom@compton.nu>
Thu, 4 Aug 2022 19:31:15 +0000 (20:31 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 4 Aug 2022 19:49:30 +0000 (20:49 +0100)
cookbooks/matomo/recipes/default.rb
cookbooks/matomo/templates/default/apache.erb

index 9b2b6302c64278b364ac31a1db670c9ce263e1a6..b916e83d7180157dfb73b244ac0af0bb7ee01eb3 100644 (file)
@@ -25,6 +25,8 @@ include_recipe "php::fpm"
 passwords = data_bag_item("matomo", "passwords")
 
 package %w[
+  brotli
+  gzip
   php-cli
   php-curl
   php-mbstring
@@ -153,6 +155,15 @@ if File.symlink?("/srv/matomo.openstreetmap.org")
     subscribes :run, "execute[core:update]"
   end
 
+  execute "/opt/matomo-#{version}/matomo/matomo.br" do
+    action :nothing
+    command "brotli -k -9 /opt/matomo-#{version}/matomo/matomo.js"
+    cwd "/opt/matomo-#{version}"
+    user "root"
+    group "root"
+    subscribes :run, "execute[custom-matomo-js:update]"
+  end
+
   execute "/opt/matomo-#{version}/matomo/matomo.js" do
     action :nothing
     command "gzip -k -9 /opt/matomo-#{version}/matomo/matomo.js"
@@ -162,6 +173,15 @@ if File.symlink?("/srv/matomo.openstreetmap.org")
     subscribes :run, "execute[custom-matomo-js:update]"
   end
 
+  execute "/opt/matomo-#{version}/matomo/piwik.br" do
+    action :nothing
+    command "brotli -k -9 /opt/matomo-#{version}/matomo/piwik.js"
+    cwd "/opt/matomo-#{version}"
+    user "root"
+    group "root"
+    subscribes :run, "execute[custom-matomo-js:update]"
+  end
+
   execute "/opt/matomo-#{version}/matomo/piwik.js" do
     action :nothing
     command "gzip -k -9 /opt/matomo-#{version}/matomo/piwik.js"
index 589d563d6ceb01826448224b607f12e410630c0f..5b503cae630e0bceb5f15fc85e4973d99d2968a4 100644 (file)
        ExpiresActive On
        RewriteEngine on
 
-       RewriteCond "%{HTTP:Accept-encoding}" "gzip"
+       RewriteCond "%{HTTP:Accept-Encoding}" "br"
+       RewriteCond "%{REQUEST_FILENAME}\.br" -s
+       RewriteRule "^(.*)\.js" "$1\.js\.br" [QSA]
+
+       RewriteCond "%{HTTP:Accept-Encoding}" "gzip"
        RewriteCond "%{REQUEST_FILENAME}\.gz" -s
        RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
 
-       RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-gzip:1]
+       RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
+
+       <FilesMatch "\.js\.br$">
+               Header append Content-Encoding br
+               Header append Vary Accept-Encoding
+       </FilesMatch>
 
        <FilesMatch "\.js\.gz$">
                Header append Content-Encoding gzip
                Header append Vary Accept-Encoding
        </FilesMatch>
 
-       <FilesMatch "(\.js|\.js\.gz)$">
+       <FilesMatch "(\.js|\.js\.gz|\.js\.br)$">
                ExpiresDefault "access plus 1 week"
                Header set Cache-Control "max-age=604800"
        </FilesMatch>