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) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-10 09:58:13 +02:00
parent 994bc618db
commit 4fe0977b71

View file

@ -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