Browser lädt nach Updates immer die aktuelle Oberfläche (Cache-Control: no-cache)
Sonst blieb nach einem Update die alte app.js im Cache: neue Buttons sichtbar, aber ohne Funktion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X48pE4bzjHej8w9HyZXCjb
This commit is contained in:
@@ -158,6 +158,16 @@ async def lifespan(app):
|
||||
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def no_stale_frontend(request: Request, call_next):
|
||||
# Nach einem Update sonst alte app.js aus dem Browser-Cache; mit no-cache fragt der Browser
|
||||
# jedes Mal kurz nach (304, wenn unverändert). Kacheln dürfen normal gecacht werden.
|
||||
resp = await call_next(request)
|
||||
if not request.url.path.startswith(("/tiles/", "/api/")):
|
||||
resp.headers["Cache-Control"] = "no-cache"
|
||||
return resp
|
||||
|
||||
|
||||
@app.get("/api/vehicles")
|
||||
def vehicles(request: Request):
|
||||
headers = {"Cache-Control": "no-store", "X-Now": str(time.time())} # für den Uhrenabgleich im Browser
|
||||
|
||||
Reference in New Issue
Block a user