mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-16 21:29:58 +01:00
Create sw.js
This commit is contained in:
committed by
GitHub
parent
18a7c4d8b4
commit
29d5885f19
35
examples/sw.js
Normal file
35
examples/sw.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const staticCacheName = 'image-sequencer-static-v3';
|
||||||
|
|
||||||
|
self.addEventListener('install', event => {
|
||||||
|
console.log('Attempting to install service worker');
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('activate', function(e) {
|
||||||
|
console.log('[ServiceWorker] Activate');
|
||||||
|
e.waitUntil(
|
||||||
|
caches.keys().then(function(cacheNames) {
|
||||||
|
return Promise.all(
|
||||||
|
cacheNames.filter(function(cacheName){
|
||||||
|
return cacheName.startsWith('image-sequencer-') &&
|
||||||
|
cacheName != staticCacheName;
|
||||||
|
}).map(function(cacheName){
|
||||||
|
return caches.delete(cacheName);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('fetch', function(event) {
|
||||||
|
event.respondWith(
|
||||||
|
caches.open(staticCacheName).then(function(cache) {
|
||||||
|
return cache.match(event.request).then(function (response) {
|
||||||
|
return response || fetch(event.request).then(function(response) {
|
||||||
|
if(event.request.method == "GET")
|
||||||
|
cache.put(event.request, response.clone());
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user