-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d9e6a8
commit 3dfae3e
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const CACHE_NAME = 'cache-v2'; | ||
const urlsToCache = [ | ||
'/index.html', | ||
'/robots.txt', | ||
'/manifest.json', | ||
'/privacy.html', | ||
'/termofuse.html', | ||
'/index.js', | ||
'/icons/icon-72x72.png', | ||
'/icons/icon-96x96.png', | ||
'/icons/icon-128x128.png', | ||
'/icons/icon-144x144.png', | ||
'/icons/icon-152x152.png', | ||
'/icons/icon-192x192.png', | ||
'/icons/icon-384x384.png', | ||
'/icons/icon-512x512.png', | ||
]; | ||
|
||
self.addEventListener('install', event => { | ||
event.waitUntil( | ||
caches.open(CACHE_NAME) | ||
.then(cache => cache.addAll(urlsToCache)) | ||
.then(() => console.log('Cache successfully initialized')) | ||
.catch(error => console.log('Cache initialization failed:', error)) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', event => { | ||
event.respondWith( | ||
caches.match(event.request) | ||
.then(response => { | ||
if (response) { | ||
return response; | ||
} | ||
return fetch(event.request); | ||
}) | ||
.catch(error => console.log('Fetch error:', error)) | ||
); | ||
}); | ||
|
||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(cacheNames => { | ||
return Promise.all( | ||
cacheNames.map(cacheName => { | ||
if (cacheName !== CACHE_NAME) { | ||
return caches.delete(cacheName); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
}); |