feat: cache-control overhaul so visual changes propagate immediately
CI / Lint (push) Successful in 14s
CI / Test (push) Successful in 12s
CI / Build & Push (push) Successful in 32s

Per-file content-hash versioning on every /static reference, immutable cache
headers on versioned URLs, no-cache on HTML, auto-bumped service worker cache
name with stale-while-revalidate for assets, and a controllerchange listener
that silently reloads the page when a new SW takes control.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-19 20:11:36 -04:00
parent aaa0899506
commit 7d1649d278
7 changed files with 110 additions and 27 deletions
+2 -2
View File
@@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#0f172a">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/static/icon-32x32.png">
<link rel="stylesheet" type="text/css" href="/static/styles.css">
<link rel="icon" type="image/png" href="{{ static_v('icon-32x32.png') }}">
<link rel="stylesheet" type="text/css" href="{{ static_v('styles.css') }}">
</head>
<body class="playoff-mode bracket-mode">
<header>
+4 -4
View File
@@ -8,9 +8,9 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="NHL Scores">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/static/icon-32x32.png">
<link rel="apple-touch-icon" href="/static/icon-180x180.png">
<link rel="stylesheet" type="text/css" href="/static/styles.css">
<link rel="icon" type="image/png" href="{{ static_v('icon-32x32.png') }}">
<link rel="apple-touch-icon" href="{{ static_v('icon-180x180.png') }}">
<link rel="stylesheet" type="text/css" href="{{ static_v('styles.css') }}">
</head>
<body>
<header>
@@ -67,6 +67,6 @@
<div id="final-games-section" class="games-grid"></div>
</section>
</main>
<script src="/static/script.js"></script>
<script src="{{ static_v('script.js') }}"></script>
</body>
</html>
+2 -2
View File
@@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#0f172a">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/static/icon-32x32.png">
<link rel="stylesheet" type="text/css" href="/static/styles.css">
<link rel="icon" type="image/png" href="{{ static_v('icon-32x32.png') }}">
<link rel="stylesheet" type="text/css" href="{{ static_v('styles.css') }}">
</head>
<body class="playoff-mode series-mode">
<header class="series-header">
+60
View File
@@ -0,0 +1,60 @@
const CACHE = 'nhl-scoreboard-{{ app_version }}';
const PRECACHE = {{ precache | tojson }};
self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE).then(c => c.addAll(PRECACHE)));
self.skipWaiting();
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
)
);
self.clients.claim();
});
self.addEventListener('fetch', event => {
if (event.request.method !== 'GET') return;
const { pathname } = new URL(event.request.url);
// Network-first for the live scoreboard API — stale data is useless
if (pathname === '/scoreboard') {
event.respondWith(
fetch(event.request).catch(() => caches.match(event.request))
);
return;
}
// Network-first for HTML pages (root, bracket, series detail) so the
// very next request after a deploy lands the new asset URLs
if (pathname === '/' || pathname === '/bracket' || pathname.startsWith('/series/')) {
event.respondWith(
fetch(event.request).then(response => {
if (response.ok) {
const clone = response.clone();
caches.open(CACHE).then(c => c.put(event.request, clone));
}
return response;
}).catch(() => caches.match(event.request))
);
return;
}
// Stale-while-revalidate for everything else (versioned static assets,
// manifest, icons): return cached bytes immediately, refresh in the
// background so the next load is current
event.respondWith(
caches.match(event.request).then(cached => {
const networkFetch = fetch(event.request).then(response => {
if (response.ok) {
const clone = response.clone();
caches.open(CACHE).then(c => c.put(event.request, clone));
}
return response;
}).catch(() => cached);
return cached || networkFetch;
})
);
});