fix(web): kein Caching der UI + versionierte Assets
Safari cachte CSS/JS aggressiv -> Aenderungen wurden nicht sichtbar. StaticFiles liefert die UI nun mit Cache-Control: no-cache aus; Asset-Links zusaetzlich versioniert (?v=3), damit die neue Version sicher geladen wird. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
a62c49d6b1
commit
b3c8114469
2 changed files with 12 additions and 3 deletions
11
app/main.py
11
app/main.py
|
|
@ -49,6 +49,15 @@ app.include_router(ws_router)
|
|||
|
||||
# Statische Web-UI (same-origin -> kein CORS). Muss NACH allen API-/WS-Routen
|
||||
# gemountet werden, damit "/" nur die uebrigen Pfade abfaengt.
|
||||
class _NoCacheStaticFiles(StaticFiles):
|
||||
"""Liefert die UI ohne Caching aus -> Aenderungen sind sofort sichtbar (kein Safari-Cache)."""
|
||||
|
||||
def file_response(self, *args, **kwargs):
|
||||
response = super().file_response(*args, **kwargs)
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
||||
return response
|
||||
|
||||
|
||||
_WEB_DIR = Path(__file__).resolve().parent / "web"
|
||||
if _WEB_DIR.is_dir():
|
||||
app.mount("/", StaticFiles(directory=str(_WEB_DIR), html=True), name="web")
|
||||
app.mount("/", _NoCacheStaticFiles(directory=str(_WEB_DIR), html=True), name="web")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue