From b0c1406cf919dede5b5e4597a75a5bf710f4617f Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 15 Nov 2016 15:37:26 +0200 Subject: [PATCH 1/2] Remove references to Cache-Control public A previous commit removed some, but missed these. Where a location directive was using Expires to set a future expiry in conjunction with Cache-Control public, I have replaced the time with an equal max-age. Furthermore, Google's web performance guide says that "public" is implicit if there is a max-age specified. See: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching --- doc/common-problems.md | 2 -- h5bp/location/cross-domain-fonts.conf | 3 +-- h5bp/location/expires.conf | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/common-problems.md b/doc/common-problems.md index 8a06c31..20fa4f5 100644 --- a/doc/common-problems.md +++ b/doc/common-problems.md @@ -148,7 +148,6 @@ will be a 404. The reason for this is that H5bp's basic ruleset includes, for ex location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { expires 1M; access_log off; - add_header Cache-Control "public"; } Which will _also_ capture any dynamic requests matching that url pattern and not @@ -166,7 +165,6 @@ Modifying (all) location blocks as follows: expires 1M; access_log off; - add_header Cache-Control "public"; } Will make Nginx pass requests for files that don't exist to the application. diff --git a/h5bp/location/cross-domain-fonts.conf b/h5bp/location/cross-domain-fonts.conf index b55ee6b..e0fa318 100644 --- a/h5bp/location/cross-domain-fonts.conf +++ b/h5bp/location/cross-domain-fonts.conf @@ -7,7 +7,6 @@ location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ { # See http://wiki.nginx.org/HttpCoreModule#location # And https://github.com/h5bp/server-configs/issues/85 # And https://github.com/h5bp/server-configs/issues/86 - expires 1M; access_log off; - add_header Cache-Control "public"; + add_header Cache-Control "max-age=2592000"; } diff --git a/h5bp/location/expires.conf b/h5bp/location/expires.conf index a1be73e..459dfd2 100644 --- a/h5bp/location/expires.conf +++ b/h5bp/location/expires.conf @@ -20,9 +20,8 @@ location ~* \.(?:rss|atom)$ { # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { - expires 1M; access_log off; - add_header Cache-Control "public"; + add_header Cache-Control "max-age=2592000"; } # CSS and Javascript From fd84b1f429245e1b9e62e5620c8c5ac4a311f4c9 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 15 Nov 2016 15:46:34 +0200 Subject: [PATCH 2/2] Use Cache-Control max-age instead of Expires headers Cache-Control max-age was introduced in HTTP/1.1 over ten years ago and is preferred to Expires. This replaces all expiry dates with an equivalent max-age in seconds. See: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching See: https://www.mnot.net/blog/2007/05/15/expires_max-age --- h5bp/location/expires.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/h5bp/location/expires.conf b/h5bp/location/expires.conf index 459dfd2..0033bd3 100644 --- a/h5bp/location/expires.conf +++ b/h5bp/location/expires.conf @@ -10,12 +10,12 @@ # cache.appcache, your document html and data location ~* \.(?:manifest|appcache|html?|xml|json)$ { - expires -1; + add_header Cache-Control "max-age=0"; } # Feed location ~* \.(?:rss|atom)$ { - expires 1h; + add_header Cache-Control "max-age=3600"; } # Media: images, icons, video, audio, HTC @@ -26,13 +26,13 @@ location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { # CSS and Javascript location ~* \.(?:css|js)$ { - expires 1y; + add_header Cache-Control "max-age=31536000"; access_log off; } # WebFonts # If you are NOT using cross-domain-fonts.conf, uncomment the following directive # location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ { -# expires 1M; +# add_header Cache-Control "max-age=2592000"; # access_log off; # }