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 @@