From ffcfe24dfbd440ab6bc397da37ac02917f11f8f4 Mon Sep 17 00:00:00 2001 From: Steppenstreuner Date: Mon, 31 Aug 2026 08:46:02 +0200 Subject: [PATCH] fix(ui/ux): make the browser revalidate the static files --- wordarr/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wordarr/main.py b/wordarr/main.py index 3594df0..8a89a9f 100644 --- a/wordarr/main.py +++ b/wordarr/main.py @@ -23,5 +23,17 @@ app.include_router(imports.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" -app.mount("/", StaticFiles(directory=static_dir, html=True), name="static") +app.mount("/", RevalidatingStatics(directory=static_dir, html=True), name="static")