Vendored modules versioned like the app's own: the 7 /vendor modules our JS imports get importmap entries and maplibre-gl.css, pmtiles and maplibre-contour a ?v=, so a deploy busts them too; a test keeps every imported /vendor module in the importmap
CI / check (push) Successful in 19s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-18 23:26:53 +01:00
1 parent a21e2b0bc6
commit 07b623b7ca
2 files changed
+34 -10

No files matched your search

+21 -10
View File
@@ -10,7 +10,7 @@
<meta name="theme-color" content="#1a1a1a">
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icons/icon-192.png">
<link rel="stylesheet" href="/vendor/maplibre-gl/maplibre-gl.css">
<link rel="stylesheet" href="/vendor/maplibre-gl/maplibre-gl.css?v=<%= ASSET_VERSION %>">
<link rel="stylesheet" href="/css/style.css?v=<%= ASSET_VERSION %>">
</head>
<body>
@@ -25,14 +25,18 @@
navigator.serviceWorker.register("/sw.js").catch(() => {});
}
</script>
<script src="/vendor/pmtiles/pmtiles.js"></script>
<script src="/vendor/maplibre-contour/maplibre-contour.min.js"></script>
<%# Vendored libs above don't change between deploys, so they're left
unversioned; app.js's own modules do, and map.js statically imports
them by bare path — an import map remaps those paths to a versioned
URL so editing e.g. gpx.js also busts its cache, without having to
touch every file's import statements. Must come before the module
script below: the importmap has to be parsed first. %>
<script src="/vendor/pmtiles/pmtiles.js?v=<%= ASSET_VERSION %>"></script>
<script src="/vendor/maplibre-contour/maplibre-contour.min.js?v=<%= ASSET_VERSION %>"></script>
<%# Every app module and every vendored module they import is versioned
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
each other — and /vendor modules — by plain path, and an import map
remaps those paths to a versioned URL, so a deploy busts all of them
without touching any import statement. A vendored module that changes
with the app (mdi.mjs gaining an icon) can't be left cached while the
module importing it is fresh. Static files are also revalidated
(static_cache_control in app.rb) as a backstop for anything loaded
some other way. Must come before the module script below: the
importmap has to be parsed first. %>
<script type="importmap">
{
"imports": {
@@ -60,7 +64,14 @@
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
"/js/sun.js": "/js/sun.js?v=<%= ASSET_VERSION %>",
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>"
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl/maplibre-gl.mjs": "/vendor/maplibre-gl/maplibre-gl.mjs?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs": "/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs?v=<%= ASSET_VERSION %>",
"/vendor/mdi/mdi.mjs": "/vendor/mdi/mdi.mjs?v=<%= ASSET_VERSION %>",
"/vendor/nps-symbols/nps-symbols.mjs": "/vendor/nps-symbols/nps-symbols.mjs?v=<%= ASSET_VERSION %>",
"/vendor/npmap-home-button/home-button.esm.js": "/vendor/npmap-home-button/home-button.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/npmap-overview/overview.esm.js": "/vendor/npmap-overview/overview.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/suncalc/suncalc.js": "/vendor/suncalc/suncalc.js?v=<%= ASSET_VERSION %>"
}
}
</script>