Skip to content

Commit

Permalink
Fixes #28739: Fix static asset caching when using Puma
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Jan 13, 2020
1 parent f273316 commit 1b0de0b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 32 deletions.
2 changes: 1 addition & 1 deletion manifests/config/apache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
if $suburi {
$custom_fragment = template('foreman/_suburi.conf.erb')
} else {
$custom_fragment = template('foreman/_assets.conf.erb')
$custom_fragment = template('foreman/_passenger_assets.conf.erb')
}

$passenger_options = {
Expand Down
64 changes: 33 additions & 31 deletions templates/_assets.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Static public dir serving
<Directory ~ <%= @docroot %>/(assets|webpack)>
# Return compressed assets if they are precompiled
<IfModule mod_rewrite.c>
RewriteEngine on
# Make sure the browser supports gzip encoding and file with .gz added
# does exist on disc before we rewrite with the extension
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME} \.(css|js|svg)$
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]

# Set headers for all possible assets which are compressed
<FilesMatch \.css\.gz$>
ForceType text/css
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.js\.gz$>
ForceType text/javascript
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.svg\.gz$>
ForceType image/svg+xml
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
</IfModule>

<LocationMatch "(assets|webpack)">
Options SymLinksIfOwnerMatch
AllowOverride None
Require all granted

# Use standard http expire header for assets instead of ETag
<IfModule mod_expires.c>
Expand All @@ -8,32 +38,4 @@
ExpiresActive On
ExpiresDefault "access plus 1 year"
</IfModule>

# Return compressed assets if they are precompiled
<IfModule mod_rewrite.c>
RewriteEngine on
# Make sure the browser supports gzip encoding and file with .gz added
# does exist on disc before we rewrite with the extension
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME} \.(css|js|svg)$
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
# Set headers for all possible assets which are compressed
<FilesMatch \.css\.gz$>
ForceType text/css
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.js\.gz$>
ForceType text/javascript
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.svg\.gz$>
ForceType image/svg+xml
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
</IfModule>

</Directory>
</LocationMatch>
39 changes: 39 additions & 0 deletions templates/_passenger_assets.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Static public dir serving
<Directory ~ <%= @docroot %>/(assets|webpack)>

# Use standard http expire header for assets instead of ETag
<IfModule mod_expires.c>
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</IfModule>

# Return compressed assets if they are precompiled
<IfModule mod_rewrite.c>
RewriteEngine on
# Make sure the browser supports gzip encoding and file with .gz added
# does exist on disc before we rewrite with the extension
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME} \.(css|js|svg)$
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
# Set headers for all possible assets which are compressed
<FilesMatch \.css\.gz$>
ForceType text/css
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.js\.gz$>
ForceType text/javascript
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
<FilesMatch \.svg\.gz$>
ForceType image/svg+xml
Header set Content-Encoding gzip
SetEnv no-gzip
</FilesMatch>
</IfModule>

</Directory>

0 comments on commit 1b0de0b

Please sign in to comment.