mirror of
https://github.com/calesthio/OpenMontage.git
synced 2026-08-11 18:01:59 +08:00
fix(backlot): no-cache header for UI pages and assets
The board is a long-lived SPA tab; browsers heuristically cache /ui assets, so UI fixes did not show up on plain refresh. Cache-Control: no-cache forces conditional revalidation (cheap ETag 304s) for /, /p/*, and /ui/* while leaving media and thumbnail caching untouched.
This commit is contained in:
@@ -277,6 +277,18 @@ def create_app() -> FastAPI:
|
||||
if UI_DIR.is_dir():
|
||||
app.mount("/ui", StaticFiles(directory=UI_DIR), name="ui")
|
||||
|
||||
# The board is a long-lived SPA: a tab keeps running whatever board.js it
|
||||
# loaded, and browsers heuristically cache /ui assets. no-cache forces a
|
||||
# conditional revalidation (cheap 304 via ETag) on every load so UI fixes
|
||||
# show up on a plain refresh. Media/thumb responses keep normal caching.
|
||||
@app.middleware("http")
|
||||
async def ui_no_cache(request, call_next):
|
||||
response = await call_next(request)
|
||||
path = request.url.path
|
||||
if path == "/" or path.startswith("/ui") or path.startswith("/p/"):
|
||||
response.headers["Cache-Control"] = "no-cache"
|
||||
return response
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user