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:
parent
994bc618db
commit
4fe0977b71
1 changed files with 3 additions and 1 deletions
4
main.py
4
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue