Skip to content

Commit ffb68e8

Browse files
committed
deploy: 5e1f617
1 parent 0763dad commit ffb68e8

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

sw.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
const CACHE_NAME = 'pushy-admin-v1';
2-
const STATIC_ASSETS = [
3-
'/',
4-
'/index.html',
5-
];
1+
const CACHE_NAME = 'pushy-admin-v2';
62

7-
// Install: precache app shell
8-
self.addEventListener('install', (event) => {
9-
event.waitUntil(
10-
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS))
11-
);
3+
// Install: activate this worker immediately without precaching the app shell.
4+
self.addEventListener('install', () => {
125
self.skipWaiting();
136
});
147

@@ -24,31 +17,34 @@ self.addEventListener('activate', (event) => {
2417
self.clients.claim();
2518
});
2619

27-
// Fetch: network-first for API, cache-first for static assets
20+
const isNavigationRequest = (request) =>
21+
request.mode === 'navigate' ||
22+
(request.headers.get('accept') || '').includes('text/html');
23+
24+
// Fetch: keep HTML/API fresh; cache only fingerprinted static assets.
2825
self.addEventListener('fetch', (event) => {
2926
const { request } = event;
3027
const url = new URL(request.url);
3128

3229
// Skip non-GET requests
3330
if (request.method !== 'GET') return;
3431

35-
// Network-first for API calls
36-
if (url.pathname.startsWith('/api')) {
37-
event.respondWith(
38-
fetch(request)
39-
.then((response) => {
40-
if (response.ok) {
41-
const clone = response.clone();
42-
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
43-
}
44-
return response;
45-
})
46-
.catch(() => caches.match(request))
47-
);
32+
if (
33+
url.origin !== self.location.origin ||
34+
isNavigationRequest(request) ||
35+
url.pathname === '/index.html' ||
36+
url.pathname === '/sw.js' ||
37+
url.pathname === '/manifest.json' ||
38+
url.pathname.startsWith('/api')
39+
) {
40+
event.respondWith(fetch(request));
41+
return;
42+
}
43+
44+
if (!url.pathname.startsWith('/static/')) {
4845
return;
4946
}
5047

51-
// Cache-first for static assets
5248
event.respondWith(
5349
caches.match(request).then((cached) => {
5450
if (cached) return cached;

0 commit comments

Comments
 (0)