working
This commit is contained in:
50
sw.js
Normal file
50
sw.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const CACHE_NAME = 'nexus-timer-cache-v3'; // Increment cache version
|
||||
const URLS_TO_CACHE = [
|
||||
'index.html',
|
||||
'style.css',
|
||||
'script.js',
|
||||
'manifest.json',
|
||||
'assets/default-avatar.svg',
|
||||
// MP3 files removed as they are no longer used
|
||||
'assets/icon-192x192.png',
|
||||
'assets/icon-512x512.png'
|
||||
];
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(cache => {
|
||||
console.log('Opened cache');
|
||||
return cache.addAll(URLS_TO_CACHE);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return fetch(event.request);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
const cacheWhitelist = [CACHE_NAME];
|
||||
event.waitUntil(
|
||||
caches.keys().then(cacheNames => {
|
||||
return Promise.all(
|
||||
cacheNames.map(cacheName => {
|
||||
if (cacheWhitelist.indexOf(cacheName) === -1) {
|
||||
console.log('Deleting old cache:', cacheName);
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user