From ca484fe861c4c24b4b1bc8da20847da73239ba17 Mon Sep 17 00:00:00 2001 From: Ashley Rich Date: Sun, 26 Nov 2017 16:36:17 +0000 Subject: [PATCH] Improve static file caching --- global/server/static-files.conf | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/global/server/static-files.conf b/global/server/static-files.conf index 626b57f..6f0b7f1 100644 --- a/global/server/static-files.conf +++ b/global/server/static-files.conf @@ -1,32 +1,40 @@ # Don't cache appcache, document html and data. location ~* \.(?:manifest|appcache|html?|xml|json)$ { - expires -1; + add_header Cache-Control "max-age=0"; } # Cache RSS and Atom feeds. location ~* \.(?:rss|atom)$ { - expires 1h; - add_header Cache-Control "public"; + add_header Cache-Control "max-age=3600"; } # Caches images, icons, video, audio, HTC, etc. -location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { - expires 1y; - add_header Cache-Control "public"; +location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ { + add_header Cache-Control "max-age=31536000"; + access_log off; +} - # Comment out these lines if you wish to record access/error logs for static files. - log_not_found off; - access_log off; +# Cache svgz files, but don't compress them. +location ~* \.svgz$ { + add_header Cache-Control "max-age=31536000"; + access_log off; + gzip off; } # Cache CSS and JavaScript. location ~* \.(?:css|js)$ { - expires 1y; - add_header Cache-Control "public"; + add_header Cache-Control "max-age=31536000"; + access_log off; +} + +# Cache WebFonts. +location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ { + add_header Cache-Control "max-age=31536000"; + access_log off; } # Don't record access/error logs for robots.txt. location = /robots.txt { - log_not_found off; access_log off; + log_not_found off; } \ No newline at end of file