Fix: Cache-Busting fuer JS/CSS (?v=Inhalts-Hash) + Cache-Control: no-cache — alte gecachte app.js ohne Such-Polling verhinderte Live-Ergebnisse

This commit is contained in:
Nicolas Gruber
2026-10-19 17:33:12 +02:00
parent 139b3677b5
commit e5b01f7c6e
2 changed files with 18 additions and 3 deletions
+16 -1
View File
@@ -1,4 +1,5 @@
"""CIS Enhanced - FastAPI app.""" """CIS Enhanced - FastAPI app."""
import hashlib
import json import json
import os import os
import threading 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"]) OWN_UID = os.environ.get("OWN_UID", os.environ["CIS_USER"])
app = FastAPI(title="CIS Enhanced") 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 = Jinja2Templates(directory=str(Path(__file__).parent / "templates"))
templates.env.globals["lv_color"] = lv_color templates.env.globals["lv_color"] = lv_color
templates.env.globals["decode_matrikel"] = decode_matrikel 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["week_label"] = week_label
templates.env.globals["slots"] = SLOTS 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(): def _meta():
return client.meta() return client.meta()
+2 -2
View File
@@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}CIS Enhanced{% endblock %} | FH-Burgenland</title> <title>{% block title %}CIS Enhanced{% endblock %} | FH-Burgenland</title>
<link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="/static/style.css?v={{ app_version }}">
</head> </head>
<body> <body>
{% set path = request.url.path %} {% set path = request.url.path %}
@@ -32,6 +32,6 @@
</div> </div>
</footer> </footer>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
<script src="/static/app.js"></script> <script src="/static/app.js?v={{ app_version }}"></script>
</body> </body>
</html> </html>