diff --git a/app.rb b/app.rb index 3f7097a..0d5781c 100644 --- a/app.rb +++ b/app.rb @@ -54,6 +54,13 @@ module Maptool class App < Sinatra::Base set :public_folder, File.join(__dir__, "public") + # Revalidate every static file (a cheap 304 when unchanged): /js and + # /css are cache-busted by ASSET_VERSION below, but the /vendor modules + # they import (mdi.mjs, nps-symbols.mjs, ...) aren't versioned — with no + # Cache-Control a browser caches them heuristically for hours, and a + # deploy that adds an export there (mdi.mjs gaining a new icon) left a + # tablet with new icons.js + stale mdi.mjs: a failed import, a blank map. + set :static_cache_control, [:no_cache] # The PWA manifest (public/manifest.webmanifest) — Rack doesn't know # this extension and would serve it as application/octet-stream. mime_type :webmanifest, "application/manifest+json" diff --git a/test/test_app.rb b/test/test_app.rb index d83a363..a3a2292 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -34,6 +34,15 @@ class AppTest < Minitest::Test end end + # Unversioned /vendor modules must be revalidated, or a deploy adding an + # export to one (imported by a freshly versioned /js module) breaks a + # browser still holding the old copy — see static_cache_control in app.rb. + def test_static_files_are_revalidated + response = request.get("/vendor/mdi/mdi.mjs") + assert_equal 200, response.status + assert_includes response.headers["Cache-Control"], "no-cache" + end + def test_offline_tiles_reports_unavailable_when_no_pmtiles_present response = request.get("/api/offline-tiles") assert_equal({ "available" => false }, json_body(response))