21 lines
447 B
JavaScript
21 lines
447 B
JavaScript
const CACHE_NAME = 'pascar';
|
|
const ASSETS = [
|
|
'index.html',
|
|
'manifest.json'
|
|
];
|
|
|
|
// Install: Cache the files
|
|
self.addEventListener('install', (e) => {
|
|
e.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
|
|
);
|
|
});
|
|
|
|
// Fetch: Serve from cache if offline
|
|
self.addEventListener('fetch', (e) => {
|
|
e.respondWith(
|
|
caches.match(e.request).then((response) => {
|
|
return response || fetch(e.request);
|
|
})
|
|
);
|
|
}); |