Improved brotli and gzip compression paths

This commit is contained in:
djmaze 2020-09-11 19:57:06 +02:00
parent 5b227de5c6
commit 4ec4771ffd
2 changed files with 79 additions and 2 deletions

75
.htaccess Normal file
View file

@ -0,0 +1,75 @@
RewriteEngine On
# Redirect cPanel
RewriteRule cpsess.* https://%{HTTP_HOST}/ [L,R=301]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css A15768000
ExpiresByType text/html A15768000
ExpiresByType application/javascript A15768000
ExpiresByType image/gif A15768000
ExpiresByType image/jpeg A15768000
ExpiresByType image/png A15768000
ExpiresByType image/svg+xml A15768000
ExpiresByType image/webp A15768000
ExpiresByType image/vnd.microsoft.icon A15768000
ExpiresByType font/woff A15768000
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=31536000"
Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; style-src 'self' 'unsafe-inline'"
Header set Referrer-Policy "no-referrer"
Header set Strict-Transport-Security "max-age=31536000"
Header set imagetoolbar "no"
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "DENY"
Header set X-XSS-Protection "1; mode=block"
</IfModule>
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-encoding} br
RewriteCond "%{REQUEST_FILENAME}\.br" -s
RewriteRule "^(.+)" "$1\.br" [L,T=text/javascript,QSA]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.+)" "$1\.gz" [L,T=text/javascript,QSA]
RewriteCond %{HTTP:Accept-encoding} br
RewriteCond "%{REQUEST_FILENAME}\.br" -s
RewriteRule "^(.+)" "$1\.br" [L,T=text/css,QSA]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.+)" "$1\.gz" [L,T=text/css,QSA]
<FilesMatch "(\.js\.br|\.css\.br)$">
SetEnv no-gzip 1
SetEnv 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
</FilesMatch>
<FilesMatch "(\.js\.gz|\.css\.gz)$">
SetEnv no-gzip 1
SetEnv no-brotli 1
# Serve correct encoding type.
Header append Content-Encoding gzip
# Force proxies to cache gzipped &
# non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
#<IfModule mod_brotli.c>
# AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
#</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css text/html text/plain text/xml application/xml text/javascript application/javascript
AddOutputFilterByType DEFLATE font/opentype font/otf font/ttf font/woff
</IfModule>

View file

@ -23,13 +23,15 @@ if ($return_var) {
if ($gzip = trim(`which gzip`)) {
// passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/*.js'), $return_var);
// passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/*.css'), $return_var);
// passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/app*.css'), $return_var);
// passthru("{$gzip} -k --best -r ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/squire/*.js'), $return_var);
}
if ($brotli = trim(`which brotli`)) {
// passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/*.js'), $return_var);
// passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/js/min/*.js'), $return_var);
// passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/*.css'), $return_var);
// passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/css/app*.css'), $return_var);
// passthru("{$brotli} -k --best ".escapeshellarg(__DIR__ . '/rainloop/v/0.0.0/static/squire/*.js'), $return_var);
}
// Temporary rename folder to speed up PharData