Skip to content

Commit 6818a06

Browse files
committed
Enable brotli compression of matomo script
1 parent 67e2c2a commit 6818a06

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

cookbooks/matomo/recipes/default.rb

+20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
passwords = data_bag_item("matomo", "passwords")
2626

2727
package %w[
28+
brotli
29+
gzip
2830
php-cli
2931
php-curl
3032
php-mbstring
@@ -153,6 +155,15 @@
153155
subscribes :run, "execute[core:update]"
154156
end
155157

158+
execute "/opt/matomo-#{version}/matomo/matomo.br" do
159+
action :nothing
160+
command "brotli -k -9 /opt/matomo-#{version}/matomo/matomo.js"
161+
cwd "/opt/matomo-#{version}"
162+
user "root"
163+
group "root"
164+
subscribes :run, "execute[custom-matomo-js:update]"
165+
end
166+
156167
execute "/opt/matomo-#{version}/matomo/matomo.js" do
157168
action :nothing
158169
command "gzip -k -9 /opt/matomo-#{version}/matomo/matomo.js"
@@ -162,6 +173,15 @@
162173
subscribes :run, "execute[custom-matomo-js:update]"
163174
end
164175

176+
execute "/opt/matomo-#{version}/matomo/piwik.br" do
177+
action :nothing
178+
command "brotli -k -9 /opt/matomo-#{version}/matomo/piwik.js"
179+
cwd "/opt/matomo-#{version}"
180+
user "root"
181+
group "root"
182+
subscribes :run, "execute[custom-matomo-js:update]"
183+
end
184+
165185
execute "/opt/matomo-#{version}/matomo/piwik.js" do
166186
action :nothing
167187
command "gzip -k -9 /opt/matomo-#{version}/matomo/piwik.js"

cookbooks/matomo/templates/default/apache.erb

+12-3
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,27 @@
5757
ExpiresActive On
5858
RewriteEngine on
5959

60-
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
60+
RewriteCond "%{HTTP:Accept-Encoding}" "br"
61+
RewriteCond "%{REQUEST_FILENAME}\.br" -s
62+
RewriteRule "^(.*)\.js" "$1\.js\.br" [QSA]
63+
64+
RewriteCond "%{HTTP:Accept-Encoding}" "gzip"
6165
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
6266
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
6367

64-
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
68+
RewriteRule "\.js\.(br|gz)$" "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
69+
70+
<FilesMatch "\.js\.br$">
71+
Header append Content-Encoding br
72+
Header append Vary Accept-Encoding
73+
</FilesMatch>
6574

6675
<FilesMatch "\.js\.gz$">
6776
Header append Content-Encoding gzip
6877
Header append Vary Accept-Encoding
6978
</FilesMatch>
7079

71-
<FilesMatch "(\.js|\.js\.gz)$">
80+
<FilesMatch "(\.js|\.js\.gz|\.js\.br)$">
7281
ExpiresDefault "access plus 1 week"
7382
Header set Cache-Control "max-age=604800"
7483
</FilesMatch>

0 commit comments

Comments
 (0)