mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-25 01:06:17 -04:00
Add ServiceWorker implementation
This commit is contained in:
parent
73c7430883
commit
2cd1798b15
2 changed files with 43 additions and 3 deletions
|
@ -0,0 +1,34 @@
|
|||
var CACHE_NAME = 'my-site-cache-v1';
|
||||
var urlsToCache = [
|
||||
'/',
|
||||
'/styles.css',
|
||||
'/scripts/network.js',
|
||||
'/scripts/ui.js',
|
||||
'/sounds/blop.mp3'
|
||||
];
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
// Perform install steps
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(function(cache) {
|
||||
console.log('Opened cache');
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(function(response) {
|
||||
// Cache hit - return response
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return fetch(event.request);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue