This commit is contained in:
parent
0dc8251ec7
commit
779500d22e
1 changed files with 14 additions and 4 deletions
|
|
@ -1,9 +1,7 @@
|
||||||
const CACHE_NAME = 'agency-cache-v1';
|
const CACHE_NAME = 'agency-cache-v2';
|
||||||
const ASSETS = [
|
const ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/src/main.js',
|
|
||||||
'/src/style.css',
|
|
||||||
'/manifest.json',
|
'/manifest.json',
|
||||||
'/icon-192.png',
|
'/icon-192.png',
|
||||||
'/icon-512.png'
|
'/icon-512.png'
|
||||||
|
|
@ -18,9 +16,21 @@ self.addEventListener('install', (event) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
|
// Only intercept http/https requests
|
||||||
|
if (!event.request.url.startsWith('http')) return;
|
||||||
|
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.match(event.request).then((response) => {
|
caches.match(event.request).then((response) => {
|
||||||
return response || fetch(event.request);
|
// Return cached response if found, otherwise fetch from network
|
||||||
|
return response || fetch(event.request).catch(error => {
|
||||||
|
// If network fetch fails and it's a navigation request, return index.html
|
||||||
|
if (event.request.mode === 'navigate') {
|
||||||
|
return caches.match('/index.html');
|
||||||
|
}
|
||||||
|
// For assets, let the browser handle the failure normally
|
||||||
|
console.error('Fetch failed:', event.request.url, error);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue