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
This commit is contained in:
1 parent
a21e2b0bc6
commit
07b623b7ca
2 files changed
+34
-10
No files matched your search
@@ -34,6 +34,19 @@ class AppTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Same for every /vendor module our own JS imports: one that changes with
|
||||||
|
# the app (mdi.mjs gaining an icon) left cached under the old URL while
|
||||||
|
# its freshly versioned importer asks for a new export is a dead page.
|
||||||
|
def test_every_imported_vendor_module_has_a_versioned_importmap_entry
|
||||||
|
response = request.get("/")
|
||||||
|
sources = Dir.glob(File.join(__dir__, "..", "public", "js", "*.js")).map { |path| File.read(path) }.join("\n")
|
||||||
|
vendor = sources.scan(%r{from\s+"(/vendor/[^"?]+)"}).flatten.uniq
|
||||||
|
refute_empty vendor
|
||||||
|
vendor.each do |path|
|
||||||
|
assert_match(%r{"#{Regexp.escape(path)}":\s*"#{Regexp.escape(path)}\?v=\d+"}, response.body, "#{path} is missing from the importmap")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Unversioned /vendor modules must be revalidated, or a deploy adding an
|
# Unversioned /vendor modules must be revalidated, or a deploy adding an
|
||||||
# export to one (imported by a freshly versioned /js module) breaks a
|
# 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.
|
# browser still holding the old copy — see static_cache_control in app.rb.
|
||||||
|
|||||||
+21
-10
@@ -10,7 +10,7 @@
|
|||||||
<meta name="theme-color" content="#1a1a1a">
|
<meta name="theme-color" content="#1a1a1a">
|
||||||
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
|
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
|
||||||
<link rel="apple-touch-icon" href="/icons/icon-192.png">
|
<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 %>">
|
<link rel="stylesheet" href="/css/style.css?v=<%= ASSET_VERSION %>">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -25,14 +25,18 @@
|
|||||||
navigator.serviceWorker.register("/sw.js").catch(() => {});
|
navigator.serviceWorker.register("/sw.js").catch(() => {});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="/vendor/pmtiles/pmtiles.js"></script>
|
<script src="/vendor/pmtiles/pmtiles.js?v=<%= ASSET_VERSION %>"></script>
|
||||||
<script src="/vendor/maplibre-contour/maplibre-contour.min.js"></script>
|
<script src="/vendor/maplibre-contour/maplibre-contour.min.js?v=<%= ASSET_VERSION %>"></script>
|
||||||
<%# Vendored libs above don't change between deploys, so they're left
|
<%# Every app module and every vendored module they import is versioned
|
||||||
unversioned; app.js's own modules do, and map.js statically imports
|
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
|
||||||
them by bare path — an import map remaps those paths to a versioned
|
each other — and /vendor modules — by plain path, and an import map
|
||||||
URL so editing e.g. gpx.js also busts its cache, without having to
|
remaps those paths to a versioned URL, so a deploy busts all of them
|
||||||
touch every file's import statements. Must come before the module
|
without touching any import statement. A vendored module that changes
|
||||||
script below: the importmap has to be parsed first. %>
|
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">
|
<script type="importmap">
|
||||||
{
|
{
|
||||||
"imports": {
|
"imports": {
|
||||||
@@ -60,7 +64,14 @@
|
|||||||
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
|
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
|
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
|
||||||
"/js/sun.js": "/js/sun.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>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user