Spaces:
Running
Running
Update src/static/sw.js
Browse files- src/static/sw.js +32 -5
src/static/sw.js
CHANGED
|
@@ -1,20 +1,47 @@
|
|
| 1 |
-
const CACHE_NAME = 'quantvat-v1';
|
| 2 |
-
const
|
| 3 |
'/',
|
| 4 |
'/static/css/base.css',
|
|
|
|
| 5 |
'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;800&display=swap'
|
| 6 |
];
|
| 7 |
|
|
|
|
| 8 |
self.addEventListener('install', (event) => {
|
| 9 |
event.waitUntil(
|
| 10 |
-
caches.open(CACHE_NAME).then((cache) => cache.addAll(
|
| 11 |
);
|
|
|
|
| 12 |
});
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
self.addEventListener('fetch', (event) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
event.respondWith(
|
| 16 |
-
caches.
|
| 17 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
})
|
| 19 |
);
|
| 20 |
});
|
|
|
|
| 1 |
+
const CACHE_NAME = 'quantvat-shell-v1';
|
| 2 |
+
const STATIC_ASSETS = [
|
| 3 |
'/',
|
| 4 |
'/static/css/base.css',
|
| 5 |
+
'/static/icons/icon-192.png',
|
| 6 |
'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;800&display=swap'
|
| 7 |
];
|
| 8 |
|
| 9 |
+
// Pre-cache the UI shell
|
| 10 |
self.addEventListener('install', (event) => {
|
| 11 |
event.waitUntil(
|
| 12 |
+
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS))
|
| 13 |
);
|
| 14 |
+
self.skipWaiting();
|
| 15 |
});
|
| 16 |
|
| 17 |
+
// Cleanup old caches
|
| 18 |
+
self.addEventListener('activate', (event) => {
|
| 19 |
+
event.waitUntil(
|
| 20 |
+
caches.keys().then((keys) => Promise.all(
|
| 21 |
+
keys.map((k) => k !== CACHE_NAME && caches.delete(k))
|
| 22 |
+
))
|
| 23 |
+
);
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
// 3. Fetch Phase: Intelligent Routing
|
| 27 |
self.addEventListener('fetch', (event) => {
|
| 28 |
+
const url = new URL(event.request.url);
|
| 29 |
+
|
| 30 |
+
// CBypass cache for API calls to ensure fresh trading data
|
| 31 |
+
if (url.pathname.startsWith('/api/') || url.pathname.includes('/tasks/')) {
|
| 32 |
+
return;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// Stale-While-Revalidate for UI
|
| 36 |
event.respondWith(
|
| 37 |
+
caches.open(CACHE_NAME).then((cache) => {
|
| 38 |
+
return cache.match(event.request).then((response) => {
|
| 39 |
+
const fetchPromise = fetch(event.request).then((networkResponse) => {
|
| 40 |
+
cache.put(event.request, networkResponse.clone());
|
| 41 |
+
return networkResponse;
|
| 42 |
+
});
|
| 43 |
+
return response || fetchPromise;
|
| 44 |
+
});
|
| 45 |
})
|
| 46 |
);
|
| 47 |
});
|