From 6c7cbf5782c23f3695acd0c079187641b48f734e Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Wed, 15 Jun 2022 13:22:18 -0500 Subject: [PATCH] Comment on context of cache-control --- helpers/astro/request.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/helpers/astro/request.js b/helpers/astro/request.js index 258d0df..f8c8269 100644 --- a/helpers/astro/request.js +++ b/helpers/astro/request.js @@ -38,6 +38,14 @@ function getMaxAgeForUrl ( Astro ) { export async function applyResponseDefaults ( Astro ) { const maxAgeSeconds = getMaxAgeForUrl( Astro ) + // 'stale-while-revalidate' tells Cloudflare to cache the response for X seconds + // but update the cache in the background + // so the user always gets a fast and cached response. + // + // This also means our Astro SSR entry function on Netlify + // only gets called from Cloudflare instead of the user's browser + // so that our actual number of requests to Netlify are minimized. + // // Cache-Control: s-maxage=1, stale-while-revalidate Astro.response.headers.set( 'Cache-Control', `s-maxage=${ maxAgeSeconds }, stale-while-revalidate` ) }