|
1 | | -const CACHE_NAME = 'trinity-v2'; |
2 | | -const BASE_PATH = '/trinity'; |
3 | | -const STATIC_ASSETS = [ |
4 | | - BASE_PATH + '/', |
5 | | - BASE_PATH + '/index.html', |
6 | | - BASE_PATH + '/vite.svg', |
7 | | - BASE_PATH + '/manifest.json' |
8 | | -]; |
9 | | - |
10 | | -// Install - cache static assets |
11 | | -self.addEventListener('install', (event) => { |
12 | | - event.waitUntil( |
13 | | - caches.open(CACHE_NAME).then((cache) => { |
14 | | - return cache.addAll(STATIC_ASSETS); |
15 | | - }) |
16 | | - ); |
| 1 | +// Self-destroying service worker - unregisters itself and clears all caches |
| 2 | +self.addEventListener('install', () => { |
17 | 3 | self.skipWaiting(); |
18 | 4 | }); |
19 | 5 |
|
20 | | -// Activate - clean old caches |
21 | 6 | self.addEventListener('activate', (event) => { |
22 | 7 | event.waitUntil( |
23 | | - caches.keys().then((keys) => { |
24 | | - return Promise.all( |
25 | | - keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)) |
26 | | - ); |
27 | | - }) |
28 | | - ); |
29 | | - self.clients.claim(); |
30 | | -}); |
31 | | - |
32 | | -// Fetch - network first, fallback to cache |
33 | | -self.addEventListener('fetch', (event) => { |
34 | | - // Skip non-GET requests |
35 | | - if (event.request.method !== 'GET') return; |
36 | | - |
37 | | - // Skip external requests |
38 | | - if (!event.request.url.startsWith(self.location.origin)) return; |
39 | | - |
40 | | - event.respondWith( |
41 | | - fetch(event.request) |
42 | | - .then((response) => { |
43 | | - // Clone and cache successful responses |
44 | | - if (response && response.status === 200 && response.type === 'basic') { |
45 | | - const clone = response.clone(); |
46 | | - caches.open(CACHE_NAME).then((cache) => { |
47 | | - cache.put(event.request, clone); |
48 | | - }); |
49 | | - } |
50 | | - return response; |
51 | | - }) |
52 | | - .catch(() => { |
53 | | - // Fallback to cache |
54 | | - return caches.match(event.request); |
| 8 | + Promise.all([ |
| 9 | + // Unregister this service worker |
| 10 | + self.registration.unregister(), |
| 11 | + // Clear all caches |
| 12 | + caches.keys().then((keys) => { |
| 13 | + return Promise.all(keys.map((key) => caches.delete(key))); |
55 | 14 | }) |
| 15 | + ]) |
56 | 16 | ); |
57 | 17 | }); |
| 18 | + |
| 19 | +// Don't intercept any requests |
| 20 | +self.addEventListener('fetch', () => {}); |
0 commit comments