From 4fe0977b719cecaf3b3dcdbd7e32cfc7297bc34f Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 10 Apr 2026 09:58:13 +0200 Subject: [PATCH] fix: also apply no-cache to root path serving index.html The StaticFiles path is empty for root "/" which served index.html via html=True. Include root/directory paths in the no-cache match. Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 78ccdeff..4ba37a37 100644 --- a/main.py +++ b/main.py @@ -3325,7 +3325,9 @@ 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. - if any(path.endswith(ext) for ext in (".html", ".js", ".css", ".json")): + # 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")): response.headers["Cache-Control"] = "no-cache, must-revalidate" return response