feat: onboarding wizard, PWA support, Oracle Cloud free tier deploy, mode nav update
This commit is contained in:
40
public/sw.js
Normal file
40
public/sw.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const CACHE_NAME = 'stackpilot-v1';
|
||||
const STATIC_ASSETS = ['/', '/index.html'];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS))
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
|
||||
)
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event;
|
||||
// Don't cache API calls
|
||||
if (request.url.includes('/api/')) {
|
||||
event.respondWith(fetch(request));
|
||||
return;
|
||||
}
|
||||
// Cache-first for static assets
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => {
|
||||
const fetched = fetch(request).then((response) => {
|
||||
if (response.ok) {
|
||||
const clone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
|
||||
}
|
||||
return response;
|
||||
}).catch(() => cached);
|
||||
return cached || fetched;
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user