From 11e467a576d07c4e8b2e88f5ab7ee78b495ec179 Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sun, 12 Jul 2026 09:54:51 +0200 Subject: [PATCH] =?UTF-8?q?fix(backend):=20cache=20headers=20for=20the=20S?= =?UTF-8?q?PA=20=E2=80=94=20no-cache=20index.html,=20immutable=20hashed=20?= =?UTF-8?q?assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phones kept showing stale builds because index.html was served without cache headers; assets/* are content-hashed and safe to cache forever. --- backend/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/main.py b/backend/main.py index ac1cf95..8dda82b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -52,8 +52,12 @@ async def spa(full_path: str): ) candidate = (DIST / full_path).resolve() if full_path else None if candidate and candidate.is_file() and candidate.is_relative_to(DIST.resolve()): - return FileResponse(candidate) - return FileResponse(DIST / "index.html") + # hashed assets are immutable; cache them hard + headers = {"Cache-Control": "public, max-age=31536000, immutable"} \ + if full_path.startswith("assets/") else {"Cache-Control": "no-cache"} + return FileResponse(candidate, headers=headers) + # index.html must always revalidate, or phones keep showing stale builds + return FileResponse(DIST / "index.html", headers={"Cache-Control": "no-cache"}) # Catch-all WS route so the charger may dial any path (it uses /).