mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
fix(cache): version static assets, update service worker to v3 with network-first navigation, and disable sw caching in nginx
This commit is contained in:
parent
1f5ea01cf3
commit
d87c4b4260
5 changed files with 47 additions and 15 deletions
|
|
@ -17,9 +17,10 @@ http {
|
|||
error_page 404 /404.html;
|
||||
add_header X-Content-Type-Options nosniff 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 {
|
||||
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;
|
||||
}
|
||||
location ~* \.(css|js|svg|png|jpg|ico|woff2?|json)$ {
|
||||
|
|
@ -28,6 +29,7 @@ http {
|
|||
}
|
||||
location / {
|
||||
try_files $uri $uri/ $uri/index.html =404;
|
||||
add_header Cache-Control "no-cache" always;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<title>Page not found — myadhd.dev</title>
|
||||
<meta name="theme-color" content="#14141c">
|
||||
<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>
|
||||
<body>
|
||||
<header class="top">
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@
|
|||
<link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<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: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:image" content="https://myadhd.dev/static/og.png">
|
||||
<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>
|
||||
<body>
|
||||
<header class="top">
|
||||
|
|
@ -387,8 +387,8 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/store.js" defer></script>
|
||||
<script src="/static/done.js" defer></script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
<script src="/static/store.js?v=3" defer></script>
|
||||
<script src="/static/done.js?v=3" defer></script>
|
||||
<script src="/static/app.js?v=3" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
|
||||
/* ---------- register service worker ---------- */
|
||||
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 ---------- */
|
||||
|
|
|
|||
40
site/sw.js
40
site/sw.js
|
|
@ -1,10 +1,13 @@
|
|||
/* myadhd.dev — service worker for offline PWA */
|
||||
var CACHE = 'myadhd-v2';
|
||||
var CACHE = 'myadhd-v3';
|
||||
var ASSETS = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/static/style.css',
|
||||
'/static/app.js',
|
||||
'/static/style.css?v=3',
|
||||
'/static/app.js?v=3',
|
||||
'/static/audio.js?v=3',
|
||||
'/static/store.js?v=3',
|
||||
'/static/done.js?v=3',
|
||||
'/static/favicon.svg',
|
||||
'/static/icon-192.png',
|
||||
'/static/icon-512.png',
|
||||
|
|
@ -12,21 +15,46 @@ var ASSETS = [
|
|||
];
|
||||
|
||||
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.addEventListener('activate', function (e) {
|
||||
e.waitUntil(
|
||||
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.addEventListener('fetch', function (e) {
|
||||
// Navigation requests: network-first so updates are picked up immediately
|
||||
if (e.request.mode === 'navigate') {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then(function (r) { return r || fetch(e.request); })
|
||||
fetch(e.request).catch(function () {
|
||||
return caches.match('/index.html') || caches.match('/');
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Static assets: cache-first with network fallback
|
||||
e.respondWith(
|
||||
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;
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue