Skip to content

Instantly share code, notes, and snippets.

@fabioyamate
Last active December 26, 2015 00:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabioyamate/7065231 to your computer and use it in GitHub Desktop.
Save fabioyamate/7065231 to your computer and use it in GitHub Desktop.
Apache2 assets config
# a2enmod headers expires
SetEnv no-gzip
<LocationMatch "^/assets/.*\.(css|js)$">
RewriteEngine on
# Make sure the browser supports gzip encoding before we send it,
# and that we have a precompiled .gz version.
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+)$ $1.gz
</LocationMatch>
<LocationMatch "^/assets/.*\.css\.gz$">
ForceType text/css
Header set Content-Encoding gzip
Header add Vary Accept-Encoding
</LocationMatch>
<LocationMatch "^/assets/.*\.js\.gz$">
ForceType application/javascript
Header set Content-Encoding gzip
Header add Vary Accept-Encoding
</LocationMatch>
# The Expires* directives requires the Apache module `mod_expires` to be enabled.
<Location /assets/>
# Use of ETag is discouraged when Last-Modified is present
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</Location>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment