From 7083cec36cbb74431f1030339ea3c7e1aebeb8fb Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sun, 6 Sep 2026 21:41:57 +0200 Subject: [PATCH] Cache-bust app JS/CSS on each deploy Browsers (and a caching proxy in front of production) were holding onto /js and /css for hours, so a deploy could go unnoticed by an already-open tab. A boot-time version query string on the entry script/stylesheet, plus an import map remapping map.js's internal module imports to the same versioned URLs, fixes that without editing every JS file's import statements. --- app.rb | 8 ++++++++ views/layout.erb | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app.rb b/app.rb index 8d0f2df..9d87cd9 100644 --- a/app.rb +++ b/app.rb @@ -20,6 +20,14 @@ module Maptool set :sessions, httponly: true, secure: production?, same_site: :lax, secret: ENV.fetch("SESSION_SECRET") { SecureRandom.hex(32) } + # Cache-busts /js and /css requests: browsers (and a caching proxy in + # front of production, see docs/deployment.adoc) hang onto static + # assets for hours, so without this a deploy that changes app.js/css + # can go unnoticed by an already-open tab until that cache expires. + # A fresh value every process start (i.e. every deploy, which restarts + # the container) is enough — it doesn't need to survive restarts. + ASSET_VERSION = Time.now.to_i + OFFLINE_PMTILES_PATH = File.join(__dir__, "data", "offline.pmtiles") GPX_STORE = GpxStore.new(File.join(__dir__, "data", "gpx")) LIVETRACK_STORE = LiveTrackStore.new(File.join(__dir__, "data", "livetrack.json")) diff --git a/views/layout.erb b/views/layout.erb index d827418..076a307 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -5,12 +5,30 @@ MapTool - + <%= yield %> - + <%# 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. %> + +