fix(ui/ux): make the browser revalidate the static files

This commit is contained in:
Steppenstreuner
2026-08-31 08:46:02 +02:00
parent b99412737e
commit ffcfe24dfb
+13 -1
View File
@@ -23,5 +23,17 @@ app.include_router(imports.router)
app.include_router(fs.router) app.include_router(fs.router)
class RevalidatingStatics(StaticFiles):
"""Without a Cache-Control header the browser caches heuristically and does
not ask again, so a redeployed app.js kept rendering the old UI. no-cache
still allows the cached copy, it just has to be revalidated first - one 304
per file per load."""
def file_response(self, *args, **kwargs): # starlette passes these positionally
resp = super().file_response(*args, **kwargs)
resp.headers["Cache-Control"] = "no-cache"
return resp
static_dir = Path(__file__).parent.parent / "static" static_dir = Path(__file__).parent.parent / "static"
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static") app.mount("/", RevalidatingStatics(directory=static_dir, html=True), name="static")