Skip to content

Instantly share code, notes, and snippets.

@ryanhefner
Created January 5, 2015 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhefner/98182cc82e7089ab0a6d to your computer and use it in GitHub Desktop.
Save ryanhefner/98182cc82e7089ab0a6d to your computer and use it in GitHub Desktop.
Optimize asset delivery on Apache servers. I typically just past this into the .htaccess file either in the root of the site, or the root of my /assets directory.
#Gzip
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
</ifModule>
#End Gzip
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
# Set Expires headers
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|svg)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</filesMatch>
</ifModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment