Files
Henglie f1394a1ab4 fix(web): stop caching settings-injected HTML
Settings are injected into index.html and the page also embeds a
per-request CSP nonce. A cached document can paint stale branding, and
answering If-None-Match with 304 while minting a new nonce makes the
browser reuse HTML whose nonce no longer matches the CSP header.

Mark every settings-injected HTML response as uncacheable for browsers
and CDN edges, and only allow 304 when the response has no nonce.
2026-11-14 13:09:07 +08:00

19 lines
660 B
Go

//go:build embed || unit
package web
import "net/http"
// applyHTMLNoCacheHeaders marks settings-injected HTML as uncacheable at every
// layer: browser memory/disk cache, back/forward cache (browsers skip bfcache
// for no-store responses) and CDN edge caches. Settings are injected into the
// document, so a stale copy would paint outdated branding until the next
// revalidation.
func applyHTMLNoCacheHeaders(header http.Header) {
header.Set("Cache-Control", "no-cache, no-store, must-revalidate")
header.Set("Pragma", "no-cache")
header.Set("Expires", "0")
header.Set("CDN-Cache-Control", "no-store")
header.Set("Surrogate-Control", "no-store")
}