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")