Merge branch 'fix/cache-busting-sw-updates' into main
All checks were successful
Build and Deploy / deploy (push) Successful in 43s

This commit is contained in:
djg 2026-09-23 20:22:21 +00:00
commit dbe509f051
5 changed files with 47 additions and 15 deletions

View file

@ -17,9 +17,10 @@ http {
error_page 404 /404.html; error_page 404 /404.html;
add_header X-Content-Type-Options nosniff always; add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always; add_header Referrer-Policy strict-origin-when-cross-origin always;
# Service worker must not be cached aggressively # Service worker must not be cached
location = /sw.js { location = /sw.js {
add_header Cache-Control "no-cache"; expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" always;
add_header X-Content-Type-Options nosniff always; add_header X-Content-Type-Options nosniff always;
} }
location ~* \.(css|js|svg|png|jpg|ico|woff2?|json)$ { location ~* \.(css|js|svg|png|jpg|ico|woff2?|json)$ {
@ -28,6 +29,7 @@ http {
} }
location / { location / {
try_files $uri $uri/ $uri/index.html =404; try_files $uri $uri/ $uri/index.html =404;
add_header Cache-Control "no-cache" always;
} }
} }
} }

View file

@ -6,7 +6,7 @@
<title>Page not found — myadhd.dev</title> <title>Page not found — myadhd.dev</title>
<meta name="theme-color" content="#14141c"> <meta name="theme-color" content="#14141c">
<link rel="icon" href="/static/favicon.svg" type="image/svg+xml"> <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="/static/style.css?v=3">
</head> </head>
<body> <body>
<header class="top"> <header class="top">

View file

@ -10,13 +10,13 @@
<link rel="icon" href="/static/favicon.svg" type="image/svg+xml"> <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/static/icon-192.png"> <link rel="apple-touch-icon" href="/static/icon-192.png">
<link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="/static/style.css?v=3">
<meta property="og:title" content="myadhd.dev — ADHD-friendly tools"> <meta property="og:title" content="myadhd.dev — ADHD-friendly tools">
<meta property="og:description" content="Break down scary tasks, tame time blindness, and build momentum. Free, no signup, data stays in your browser."> <meta property="og:description" content="Break down scary tasks, tame time blindness, and build momentum. Free, no signup, data stays in your browser.">
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:image" content="https://myadhd.dev/static/og.png"> <meta property="og:image" content="https://myadhd.dev/static/og.png">
<meta property="og:url" content="https://myadhd.dev/"> <meta property="og:url" content="https://myadhd.dev/">
<script src="/static/audio.js" defer></script> <script src="/static/audio.js?v=3" defer></script>
</head> </head>
<body> <body>
<header class="top"> <header class="top">
@ -387,8 +387,8 @@
</div> </div>
</div> </div>
<script src="/static/store.js" defer></script> <script src="/static/store.js?v=3" defer></script>
<script src="/static/done.js" defer></script> <script src="/static/done.js?v=3" defer></script>
<script src="/static/app.js" defer></script> <script src="/static/app.js?v=3" defer></script>
</body> </body>
</html> </html>

View file

@ -11,7 +11,9 @@
/* ---------- register service worker ---------- */ /* ---------- register service worker ---------- */
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').catch(function () {}); navigator.serviceWorker.register('/sw.js').then(function (reg) {
if (reg) reg.update();
}).catch(function () {});
} }
/* ---------- audio helpers ---------- */ /* ---------- audio helpers ---------- */

View file

@ -1,10 +1,13 @@
/* myadhd.dev — service worker for offline PWA */ /* myadhd.dev — service worker for offline PWA */
var CACHE = 'myadhd-v2'; var CACHE = 'myadhd-v3';
var ASSETS = [ var ASSETS = [
'/', '/',
'/index.html', '/index.html',
'/static/style.css', '/static/style.css?v=3',
'/static/app.js', '/static/app.js?v=3',
'/static/audio.js?v=3',
'/static/store.js?v=3',
'/static/done.js?v=3',
'/static/favicon.svg', '/static/favicon.svg',
'/static/icon-192.png', '/static/icon-192.png',
'/static/icon-512.png', '/static/icon-512.png',
@ -12,21 +15,46 @@ var ASSETS = [
]; ];
self.addEventListener('install', function (e) { self.addEventListener('install', function (e) {
e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(ASSETS); })); e.waitUntil(
caches.open(CACHE).then(function (c) {
return c.addAll(ASSETS);
})
);
self.skipWaiting(); self.skipWaiting();
}); });
self.addEventListener('activate', function (e) { self.addEventListener('activate', function (e) {
e.waitUntil( e.waitUntil(
caches.keys().then(function (names) { caches.keys().then(function (names) {
return Promise.all(names.filter(function (n) { return n !== CACHE; }).map(function (n) { return caches.delete(n); })); return Promise.all(
names.filter(function (n) { return n !== CACHE; }).map(function (n) { return caches.delete(n); })
);
}) })
); );
self.clients.claim(); self.clients.claim();
}); });
self.addEventListener('fetch', function (e) { self.addEventListener('fetch', function (e) {
// Navigation requests: network-first so updates are picked up immediately
if (e.request.mode === 'navigate') {
e.respondWith(
fetch(e.request).catch(function () {
return caches.match('/index.html') || caches.match('/');
})
);
return;
}
// Static assets: cache-first with network fallback
e.respondWith( e.respondWith(
caches.match(e.request).then(function (r) { return r || fetch(e.request); }) caches.match(e.request).then(function (r) {
return r || fetch(e.request).then(function (res) {
if (res && res.status === 200 && e.request.url.startsWith(self.location.origin)) {
var copy = res.clone();
caches.open(CACHE).then(function (cache) { cache.put(e.request, copy); });
}
return res;
});
})
); );
}); });