From 2a809a9a0b9f4f7631e08bb77d257f2ba13b7b08 Mon Sep 17 00:00:00 2001 From: rene Date: Fri, 5 Jun 2026 19:18:43 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Tiles-Cache-Bust=20=E2=80=94=20versionie?= =?UTF-8?q?rte=20PMTiles-URL=20+=20version-bewusstes=20Caching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'nur DACH auf Staging' Ursache: serve_tile schickte Cache-Control max-age=86400 OHNE Validator → Browser lieferte bis 24h die ALTEN PMTiles-Bytes (altes Directory) trotz Datei-Swap. Fix: - map-gl-style.js: tilesUrl() hängt ?v=TILES_VER an (Cache-Bust bei Tile-Deploy) - serve_tile: ?v vorhanden → max-age=1y immutable; ohne → max-age=60 (self-heal) + ETag - Makefile tiles-deploy zählt TILES_VER automatisch hoch + erinnert an Frontend-Deploy --- Makefile | 4 ++++ VERSION | 2 +- backend/main.py | 9 ++++++++- backend/static/index.html | 24 ++++++++++++------------ backend/static/js/app.js | 2 +- backend/static/js/map-gl-style.js | 6 +++++- backend/static/landing.html | 2 +- backend/static/sw.js | 2 +- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index e8d24b1..4c7cefe 100644 --- a/Makefile +++ b/Makefile @@ -185,6 +185,10 @@ tiles-deploy: check-ssh @scp -O $(TILES_DIR)/dach.pmtiles $(DS_HOST):$(TILES_TARGET)/data/tiles/dach.pmtiles.tmp @ssh $(DS_HOST) "mv -f $(TILES_TARGET)/data/tiles/dach.pmtiles.tmp $(TILES_TARGET)/data/tiles/dach.pmtiles" @echo " ✓ dach.pmtiles ausgeliefert ($(if $(filter prod,$(ENV)),PRODUKTION,Staging))" + @# Cache-Bust: TILES_VER in map-gl-style.js hochzählen (sonst liefert der Browser bis 24h alte Tiles). + @NEWVER=$$(date +%Y%m%d%H%M); \ + sed -i '' "s/var TILES_VER = '[0-9]*';/var TILES_VER = '$$NEWVER';/" backend/static/js/map-gl-style.js; \ + echo " ↻ TILES_VER → $$NEWVER — JETZT Frontend ausliefern: make bump && make $(if $(filter prod,$(ENV)),deploy,staging)" # ---------------------------------------------------------- # RELEASE — develop → main → Production (VERSION= pflichtangabe) diff --git a/VERSION b/VERSION index b5811ff..24d3bec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1207 \ No newline at end of file +1208 \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 201cb60..bf4f74b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -396,7 +396,14 @@ async def serve_tile(filename: str, request: Request): if not os.path.isfile(path): return Response(status_code=404) file_size = os.path.getsize(path) - base_headers = {"Accept-Ranges": "bytes", "Cache-Control": "public, max-age=86400"} + _mtime = int(os.path.getmtime(path)) + _etag = f'"{file_size:x}-{_mtime:x}"' + # Versionierte URL (?v=…) ist inhaltsstabil → lange + immutable cachen. OHNE Version nur kurz cachen, + # damit ein Tile-Swap (gleiche URL, neuer Inhalt) sich innerhalb ~1 Min von selbst heilt — sonst + # liefert der Browser bis zu 24h die alten PMTiles-Bytes (alte Abdeckung). + _versioned = "v" in request.query_params + _cache = "public, max-age=31536000, immutable" if _versioned else "public, max-age=60" + base_headers = {"Accept-Ranges": "bytes", "Cache-Control": _cache, "ETag": _etag} if request.method == "HEAD": return Response( status_code=200, media_type="application/octet-stream", diff --git a/backend/static/index.html b/backend/static/index.html index 9bf8a7b..3fa21ed 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -86,14 +86,14 @@ Ban Yaro - + - - - - - + + + + + @@ -617,11 +617,11 @@ - - - - - + + + + + @@ -631,7 +631,7 @@ - + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index d1d6ff9..d43b455 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '1207'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '1208'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator) window.APP_VERSION = APP_VERSION; diff --git a/backend/static/js/map-gl-style.js b/backend/static/js/map-gl-style.js index 7fcf803..ac14f95 100644 --- a/backend/static/js/map-gl-style.js +++ b/backend/static/js/map-gl-style.js @@ -6,7 +6,11 @@ 'use strict'; var TILES_FILE = 'dach.pmtiles'; - function tilesUrl() { return window.location.origin + '/tiles/' + TILES_FILE; } + // Cache-Bust: gleiche Datei-URL, aber Inhalt ändert sich bei jedem Tile-Deploy (atomarer Swap). + // Ohne Versions-Param liefert der Browser bis zu 24h die ALTEN PMTiles-Bytes (inkl. altem Directory) + // → man sähe die alte Abdeckung. Bei jedem `make tiles-deploy` HOCHZÄHLEN (Makefile sed't das). + var TILES_VER = '20260605'; + function tilesUrl() { return window.location.origin + '/tiles/' + TILES_FILE + '?v=' + TILES_VER; } var THEMES = { light: { diff --git a/backend/static/landing.html b/backend/static/landing.html index 4f46967..9af14db 100644 --- a/backend/static/landing.html +++ b/backend/static/landing.html @@ -4,7 +4,7 @@ - + Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz diff --git a/backend/static/sw.js b/backend/static/sw.js index 49882fb..a0316c9 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -4,7 +4,7 @@ ============================================================ */ // ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab -const VER = '1207'; +const VER = '1208'; const CACHE_VERSION = `by-v${VER}`; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten