From 21e72b438f6d2c3b1d7a787c5e405dea0b913fe3 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 10 Apr 2026 09:59:03 +0200 Subject: [PATCH] fix: use content-type instead of path for no-cache detection Root "/" path doesn't match .html ending. Checking the response's content-type header catches index.html served via html=True and is more robust for any URL that returns HTML/JS/CSS/JSON. Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 4ba37a37..3d10310a 100644 --- a/main.py +++ b/main.py @@ -3325,9 +3325,10 @@ class NoCacheStaticFiles(StaticFiles): response = await super().get_response(path, scope) # Force revalidation for HTML/JS/CSS/JSON so code changes show up # immediately after git pull. Other assets (images, fonts) can cache. - # Empty path ("") or paths ending in / resolve to index.html via html=True. - is_html_route = path == "" or path.endswith("/") or path.endswith(".html") - if is_html_route or any(path.endswith(ext) for ext in (".js", ".css", ".json")): + # Check content-type header since root path "" resolves to index.html + # via html=True and we need to catch it too. + ct = response.headers.get("content-type", "").lower() + if any(t in ct for t in ("text/html", "javascript", "text/css", "application/json")): response.headers["Cache-Control"] = "no-cache, must-revalidate" return response