From e5b01f7c6ef59d28033000044c84f7a2485f56fc Mon Sep 17 00:00:00 2001 From: Nicolas Gruber Date: Mon, 19 Oct 2026 17:33:12 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Cache-Busting=20fuer=20JS/CSS=20(=3Fv=3D?= =?UTF-8?q?Inhalts-Hash)=20+=20Cache-Control:=20no-cache=20=E2=80=94=20alt?= =?UTF-8?q?e=20gecachte=20app.js=20ohne=20Such-Polling=20verhinderte=20Liv?= =?UTF-8?q?e-Ergebnisse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 17 ++++++++++++++++- app/templates/base.html | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index c2f4d5a..493e92e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,5 @@ """CIS Enhanced - FastAPI app.""" +import hashlib import json import os import threading @@ -33,7 +34,8 @@ client = CISClient(os.environ["CIS_USER"], os.environ["CIS_PASSWORD"], BASE) OWN_UID = os.environ.get("OWN_UID", os.environ["CIS_USER"]) app = FastAPI(title="CIS Enhanced") -app.mount("/static", StaticFiles(directory=str(Path(__file__).parent / "static")), name="static") +_STATIC_DIR = Path(__file__).parent / "static" +app.mount("/static", StaticFiles(directory=str(_STATIC_DIR)), name="static") templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates")) templates.env.globals["lv_color"] = lv_color templates.env.globals["decode_matrikel"] = decode_matrikel @@ -41,6 +43,19 @@ templates.env.globals["fmt_range"] = fmt_range templates.env.globals["week_label"] = week_label templates.env.globals["slots"] = SLOTS +# Cache-Busting: Version = Hash der JS/CSS-Inhalte (neue URL => kein veralteter Browser-Cache) +_APP_HASH = hashlib.md5( + (_STATIC_DIR / "app.js").read_bytes() + (_STATIC_DIR / "style.css").read_bytes() +).hexdigest()[:10] +templates.env.globals["app_version"] = _APP_HASH + + +@app.middleware("http") +async def _no_cache(request: Request, call_next): + resp = await call_next(request) + resp.headers["Cache-Control"] = "no-cache" + return resp + def _meta(): return client.meta() diff --git a/app/templates/base.html b/app/templates/base.html index 1de0dab..c45ae3b 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -4,7 +4,7 @@ {% block title %}CIS Enhanced{% endblock %} | FH-Burgenland - + {% set path = request.url.path %} @@ -32,6 +32,6 @@ {% block scripts %}{% endblock %} - +