Fix permanent: JS/CSS nie immutable cachen — verhindert Update-Loop (SW by-v890)

Browser-HTTP-Cache mit immutable lässt sich nach force-update nicht leeren.
Veraltete app.js (APP_VER alt) führt zu X-App-Version Mismatch → Dauerschleife.
SW übernimmt Caching sowieso → no-cache für alle JS/CSS ist sicher.
This commit is contained in:
rene 2026-05-12 19:41:26 +02:00
parent 437901b8e2
commit a5b8174566
4 changed files with 11 additions and 13 deletions

View file

@ -156,17 +156,15 @@ app.add_middleware(_AppVersionMiddleware)
class _CacheControlMiddleware(BaseHTTPMiddleware): class _CacheControlMiddleware(BaseHTTPMiddleware):
"""Setzt Cache-Control-Header für statische Assets. """Setzt Cache-Control-Header für statische Assets.
CSS/JS: no-cache (ETag-Validierung) iOS cached sonst ewig ohne Ablaufdatum. JS/CSS: immer no-cache SW übernimmt Caching. Immutable wäre gefährlich,
Versioned Assets (?v=): immutable URL ändert sich bei Updates. weil Browser-HTTP-Cache nach force-update nicht geleert wird und veraltete
app.js mit falschem APP_VER eine Update-Dauerschleife verursacht.
""" """
async def dispatch(self, request: Request, call_next): async def dispatch(self, request: Request, call_next):
response = await call_next(request) response = await call_next(request)
path = request.url.path path = request.url.path
if path.startswith(("/css/", "/js/", "/icons/phosphor.svg")): if path.startswith(("/css/", "/js/", "/icons/phosphor.svg")):
if "v=" in str(request.url.query): response.headers["Cache-Control"] = "no-cache, must-revalidate"
response.headers["Cache-Control"] = "public, max-age=31536000, immutable"
else:
response.headers["Cache-Control"] = "no-cache, must-revalidate"
return response return response
app.add_middleware(_CacheControlMiddleware) app.add_middleware(_CacheControlMiddleware)
@ -406,7 +404,7 @@ async def serve_media(path: str, request: _Request):
raise _HE(404, "Nicht gefunden.") raise _HE(404, "Nicht gefunden.")
return _media_response(filepath) return _media_response(filepath)
APP_VER = "889" # muss mit APP_VER in app.js übereinstimmen APP_VER = "890" # muss mit APP_VER in app.js übereinstimmen
@app.get("/.well-known/assetlinks.json") @app.get("/.well-known/assetlinks.json")
async def assetlinks(): async def assetlinks():

View file

@ -583,10 +583,10 @@
<div id="modal-container"></div> <div id="modal-container"></div>
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features --> <!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
<script src="/js/api.js?v=888"></script> <script src="/js/api.js?v=890"></script>
<script src="/js/ui.js?v=888"></script> <script src="/js/ui.js?v=890"></script>
<script src="/js/app.js?v=888"></script> <script src="/js/app.js?v=890"></script>
<script src="/js/worlds.js?v=888"></script> <script src="/js/worlds.js?v=890"></script>
<!-- Feature-Seiten werden lazy geladen --> <!-- Feature-Seiten werden lazy geladen -->

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung. Router, State-Management, Navigation, Initialisierung.
============================================================ */ ============================================================ */
const APP_VER = '889'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VER = '890'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.5.1'; // ← semantische Version, wird bei make release gesetzt const APP_VERSION = '1.5.1'; // ← semantische Version, wird bei make release gesetzt
const IS_STAGING = location.hostname === 'staging.banyaro.app'; const IS_STAGING = location.hostname === 'staging.banyaro.app';
// Cache-Bust-Parameter nach Update-Reload sofort entfernen // Cache-Bust-Parameter nach Update-Reload sofort entfernen

View file

@ -3,7 +3,7 @@
Offline-Cache + Push Notifications + Tile-Cache Offline-Cache + Push Notifications + Tile-Cache
============================================================ */ ============================================================ */
const CACHE_VERSION = 'by-v889'; const CACHE_VERSION = 'by-v890';
const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_STATIC = `${CACHE_VERSION}-static`;
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache