From 878793d74ba70296873bb94443d7f84342e532af Mon Sep 17 00:00:00 2001 From: Star Date: Thu, 5 Mar 2026 17:00:26 +0800 Subject: [PATCH] fix: prevent CDN from caching 404 responses for static assets - add_no_cache_headers now only applies long-cache headers to 2xx responses - non-2xx static responses (e.g. 404) get no-cache to prevent CDN from caching error pages (which was the root cause of office.hyacinth.im failing to load - Cloudflare cached a 404 for phaser.js for 2.7 days) - add version cache-bust param to phaser.js script tag (matching all other static assets) --- backend/app.py | 5 +++-- frontend/index.html | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/app.py b/backend/app.py index 90af2b8..1b6091e 100644 --- a/backend/app.py +++ b/backend/app.py @@ -109,10 +109,11 @@ def _require_asset_editor_auth(): def add_no_cache_headers(response): """Apply cache policy by path: - HTML/API/state: no-cache (always fresh) - - /static assets: long cache (filenames are versioned with ?v=VERSION_TIMESTAMP) + - /static assets (2xx only): long cache (filenames are versioned with ?v=VERSION_TIMESTAMP) + - /static assets (non-2xx, e.g. 404): no-cache to prevent CDN from caching errors """ path = (request.path or "") - if path.startswith('/static/'): + if path.startswith('/static/') and 200 <= response.status_code < 300: response.headers["Cache-Control"] = "public, max-age=31536000, immutable" response.headers.pop("Pragma", None) response.headers.pop("Expires", None) diff --git a/frontend/index.html b/frontend/index.html index d1d2a98..9dc9402 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1259,7 +1259,7 @@ - +