|
1 | | -const CACHE_NAME = '9ruby-v1'; |
2 | | -const OFFLINE_URL = '/offline.html'; |
3 | | - |
4 | | -const PRECACHE_URLS = [ |
5 | | - '/', |
6 | | - '/offline.html', |
7 | | - '/manifest.json', |
8 | | - '/icons/icon-192.png', |
9 | | - '/icons/icon-512.png', |
10 | | -]; |
11 | | - |
12 | | -// Install — precache the app shell and offline page |
13 | | -self.addEventListener('install', (event) => { |
14 | | - event.waitUntil( |
15 | | - caches.open(CACHE_NAME).then((cache) => cache.addAll(PRECACHE_URLS)) |
16 | | - ); |
| 1 | +// 9Ruby no longer uses a service worker for the public site preview. |
| 2 | +// This self-destructing worker removes old cached assets so refreshes cannot |
| 3 | +// serve stale CSS/JS or old adaptive layouts. |
| 4 | +self.addEventListener('install', () => { |
17 | 5 | self.skipWaiting(); |
18 | 6 | }); |
19 | 7 |
|
20 | | -// Activate — clean up old caches |
21 | 8 | self.addEventListener('activate', (event) => { |
22 | 9 | event.waitUntil( |
23 | | - caches.keys().then((keys) => |
24 | | - Promise.all( |
25 | | - keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)) |
26 | | - ) |
27 | | - ) |
| 10 | + Promise.all([ |
| 11 | + caches.keys().then((keys) => Promise.all(keys.map((key) => caches.delete(key)))), |
| 12 | + self.registration.unregister(), |
| 13 | + self.clients.matchAll({ type: 'window' }).then((clients) => |
| 14 | + Promise.all(clients.map((client) => client.navigate(client.url))) |
| 15 | + ), |
| 16 | + ]) |
28 | 17 | ); |
29 | | - self.clients.claim(); |
30 | 18 | }); |
31 | 19 |
|
32 | | -// Fetch — network-first with offline fallback |
33 | | -self.addEventListener('fetch', (event) => { |
34 | | - // Only handle GET requests |
35 | | - if (event.request.method !== 'GET') return; |
36 | | - |
37 | | - // Skip non-http(s) requests (e.g. chrome-extension://) |
38 | | - if (!event.request.url.startsWith('http')) return; |
39 | | - |
40 | | - event.respondWith( |
41 | | - fetch(event.request) |
42 | | - .then((response) => { |
43 | | - // Clone and cache successful responses |
44 | | - if (response && response.status === 200) { |
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(async () => { |
53 | | - // Network failed — try the cache |
54 | | - const cached = await caches.match(event.request); |
55 | | - if (cached) return cached; |
56 | | - |
57 | | - // For navigation requests, show the offline page |
58 | | - if (event.request.mode === 'navigate') { |
59 | | - return caches.match(OFFLINE_URL); |
60 | | - } |
61 | | - |
62 | | - // Return a basic error response for other requests |
63 | | - return new Response('Offline', { |
64 | | - status: 503, |
65 | | - statusText: 'Service Unavailable', |
66 | | - }); |
67 | | - }) |
68 | | - ); |
| 20 | +self.addEventListener('fetch', () => { |
| 21 | + // Do not intercept requests. Network/browser cache should be the source of truth. |
69 | 22 | }); |
0 commit comments