|
|
const CACHE_NAME = 'ghostboard-v1'; |
|
|
const ASSETS = [ |
|
|
'/', |
|
|
'/static/images/icon.svg', |
|
|
'/static/manifest.json', |
|
|
'https://cdn.tailwindcss.com', |
|
|
'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js' |
|
|
]; |
|
|
|
|
|
self.addEventListener('install', (e) => { |
|
|
e.waitUntil( |
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)) |
|
|
); |
|
|
}); |
|
|
|
|
|
self.addEventListener('fetch', (e) => { |
|
|
|
|
|
if (e.request.mode === 'navigate') { |
|
|
e.respondWith( |
|
|
fetch(e.request).catch(() => { |
|
|
return caches.match(e.request).then(response => { |
|
|
if (response) return response; |
|
|
|
|
|
return caches.match('/'); |
|
|
}); |
|
|
}) |
|
|
); |
|
|
} else { |
|
|
e.respondWith( |
|
|
caches.match(e.request).then((response) => { |
|
|
return response || fetch(e.request); |
|
|
}) |
|
|
); |
|
|
} |
|
|
}); |
|
|
|