From b5ab776a2383ac4f3ab3d89a85dc39e864a9cc02 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sun, 21 Sep 2025 05:31:04 +0000 Subject: [PATCH] Use `Cache-Control: max-age=60, stale-while-revalidate=3600`. This is a way to avoid blocking on network requests in the browser while ensuring the content is served very fresh. --- src/pages.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages.go b/src/pages.go index 311c730..7992f3f 100644 --- a/src/pages.go +++ b/src/pages.go @@ -156,9 +156,13 @@ func getPage(w http.ResponseWriter, r *http.Request) error { w.Header().Set("Cross-Origin-Embedder-Policy", "credentialless") w.Header().Set("Cross-Origin-Opener-Policy", "same-origin") - // always check whether content has changed with the origin server; it is cheap to handle - // ETag or If-Modified-Since queries and it avoids stale content being served - w.Header().Set("Cache-Control", "public, max-age=0, must-revalidate") + // consider content fresh for 60 seconds (the same as the freshness interval of + // manifests in the S3 backend), and use stale content anyway as long as it's not + // older than a hour; while it is cheap to handle If-Modified-Since queries + // server-side, on the client `max-age=0, must-revalidate` causes every resource + // to block the page load every time + w.Header().Set("Cache-Control", "max-age=60, stale-while-revalidate=3600") + // see https://web.dev/articles/stale-while-revalidate for details // http.ServeContent handles content type and caching http.ServeContent(w, r, sitePath, mtime, reader)