16 lines
655 B
JavaScript
16 lines
655 B
JavaScript
const CACHE_NAME = 'traveler-tools-v1';
|
|
const ASSETS = ['./', 'index.html', 'traveler-tools.js', '../shared.css', 'manifest.webmanifest'];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)));
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)))));
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
if (event.request.method !== 'GET') return;
|
|
event.respondWith(caches.match(event.request).then((cached) => cached || fetch(event.request)));
|
|
});
|