From 09e517ee4e5f948631c36b6a3a4a172e679d0eb7 Mon Sep 17 00:00:00 2001 From: S Anand Date: Mon, 13 May 2013 08:57:51 +0530 Subject: [PATCH] Merged compression and expires headers sections from HTML5Boilerplate https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess --- .htaccess | 111 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 33 deletions(-) diff --git a/.htaccess b/.htaccess index c5ce5fc4be..549b6e65be 100644 --- a/.htaccess +++ b/.htaccess @@ -37,45 +37,90 @@ RewriteRule (.*) public/$1 [L] # Default expires header if none specified (stay in browser cache for 7 days) - ExpiresActive On - ExpiresDefault A604800 - - ExpiresByType application/javascript "access plus 2 hours" - ExpiresByType application/x-javascript "access plus 2 hours" - ExpiresByType text/javascript "access plus 2 hours" - ExpiresByType text/x-javascript "access plus 2 hours" - ExpiresByType text/css "access plus 2 hours" - ExpiresByType image/gif "access plus 2 hours" - ExpiresByType image/jpg "access plus 2 hours" - ExpiresByType image/png "access plus 2 hours" - ExpiresByType image/x-icon "access plus 2 hours" - -# set compression - - - # Insert filter - SetOutputFilter DEFLATE + ExpiresActive on + ExpiresDefault "access plus 1 week" + + # CSS + ExpiresByType text/css "access plus 1 year" + + # Data interchange + ExpiresByType application/json "access plus 0 seconds" + ExpiresByType application/xml "access plus 0 seconds" + ExpiresByType text/xml "access plus 0 seconds" + + # Favicon (cannot be renamed!) + ExpiresByType image/x-icon "access plus 1 week" - # Netscape 4.x has some problems... - BrowserMatch ^Mozilla/4 gzip-only-text/html + # HTML components (HTCs) + ExpiresByType text/x-component "access plus 1 month" - # Netscape 4.06-4.08 have some more problems - BrowserMatch ^Mozilla/4\.0[678] no-gzip + # HTML + ExpiresByType text/html "access plus 0 seconds" - # MSIE masquerades as Netscape, but it is fine - # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html + # JavaScript + ExpiresByType application/javascript "access plus 1 year" - # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 - # the above regex won't work. You can use the following - # workaround to get the desired effect: - BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html + # Manifest files + ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds" + ExpiresByType text/cache-manifest "access plus 0 seconds" - # Don't compress images - SetEnvIfNoCase Request_URI \ - \.(?:gif|jpe?g|png)$ no-gzip dont-vary + # Media + ExpiresByType audio/ogg "access plus 1 month" + ExpiresByType image/gif "access plus 1 month" + ExpiresByType image/jpeg "access plus 1 month" + ExpiresByType image/png "access plus 1 month" + ExpiresByType video/mp4 "access plus 1 month" + ExpiresByType video/ogg "access plus 1 month" + ExpiresByType video/webm "access plus 1 month" - # Make sure proxies don't deliver the wrong content - Header append Vary User-Agent env=!dont-vary + # Web feeds + ExpiresByType application/atom+xml "access plus 1 hour" + ExpiresByType application/rss+xml "access plus 1 hour" + + # Web fonts + ExpiresByType application/font-woff "access plus 1 month" + ExpiresByType application/vnd.ms-fontobject "access plus 1 month" + ExpiresByType application/x-font-ttf "access plus 1 month" + ExpiresByType font/opentype "access plus 1 month" + ExpiresByType image/svg+xml "access plus 1 month" + + + + + + + # Force compression for mangled headers. + # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping + + + SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding + RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding + + + # Compress all output labeled with one of the following MIME-types + # (for Apache versions below 2.3.7, you don't need to enable `mod_filter` + # and can remove the `` and `` lines + # as `AddOutputFilterByType` is still in the core directives). + + AddOutputFilterByType DEFLATE application/atom+xml \ + application/javascript \ + application/json \ + application/rss+xml \ + application/vnd.ms-fontobject \ + application/x-font-ttf \ + application/x-web-app-manifest+json \ + application/xhtml+xml \ + application/xml \ + font/opentype \ + image/svg+xml \ + image/x-icon \ + text/css \ + text/html \ + text/plain \ + text/x-component \ + text/xml + +