From 5003d3ec090ac83f05c6a32890261a8acc52050d Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Mar 2026 14:57:59 -0400 Subject: [PATCH] Fix stale UI cache with network-first app shell and forced SW updates --- app/public/index.html | 13 ++++++++++++- app/public/sw.js | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/public/index.html b/app/public/index.html index 33c49e2..48ee8bc 100644 --- a/app/public/index.html +++ b/app/public/index.html @@ -297,7 +297,18 @@ diff --git a/app/public/sw.js b/app/public/sw.js index 05deeb3..2a33ee8 100644 --- a/app/public/sw.js +++ b/app/public/sw.js @@ -1,6 +1,6 @@ 'use strict'; -const CACHE = 'weather-v2'; +const CACHE = 'weather-v3'; // App shell — cached on install for offline use const PRECACHE = [ @@ -45,6 +45,28 @@ self.addEventListener('fetch', event => { return; } + const isAppShellRequest = + request.mode === 'navigate' || + request.destination === 'document' || + request.destination === 'script' || + request.destination === 'style'; + + // Prefer fresh app shell assets so UI updates are visible immediately. + if (isAppShellRequest) { + event.respondWith( + fetch(request) + .then(response => { + if (response.ok) { + const clone = response.clone(); + caches.open(CACHE).then(cache => cache.put(request, clone)); + } + return response; + }) + .catch(() => caches.match(request).then(cached => cached || caches.match('/'))) + ); + return; + } + event.respondWith( caches.match(request).then(cached => { if (cached) return cached;