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 Feb 12, 2020
1 parent 9c1787a commit 641dce0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
41 changes: 41 additions & 0 deletions files/_assets.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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>
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</IfModule>
</LocationMatch>
4 changes: 2 additions & 2 deletions 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 = file('foreman/_assets.conf.erb')
}

$passenger_options = {
Expand All @@ -128,7 +128,7 @@
if $suburi {
$custom_fragment = undef
} else {
$custom_fragment = template('foreman/_assets.conf.erb')
$custom_fragment = file('foreman/_assets.conf.erb')
}

include ::apache::mod::proxy_wstunnel
Expand Down
39 changes: 0 additions & 39 deletions templates/_assets.conf.erb

This file was deleted.

0 comments on commit 641dce0

Please sign in to comment.