diff options
author | elioat <elioat@tilde.institute> | 2024-06-30 18:30:33 -0400 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-06-30 18:30:33 -0400 |
commit | f29758cfe8e233fa9d011f3eb7083123bfd40cd5 (patch) | |
tree | 8698edceae1f1fb467b533343f1316a53b7cf11d /js/pico-cam/service-worker.js | |
parent | bcdc7c3b2b74cdce311d569c78fc2adee0a66b12 (diff) | |
download | tour-f29758cfe8e233fa9d011f3eb7083123bfd40cd5.tar.gz |
*
Diffstat (limited to 'js/pico-cam/service-worker.js')
-rw-r--r-- | js/pico-cam/service-worker.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/js/pico-cam/service-worker.js b/js/pico-cam/service-worker.js new file mode 100644 index 0000000..75027ed --- /dev/null +++ b/js/pico-cam/service-worker.js @@ -0,0 +1,45 @@ +var CACHE_NAME = 'pico-cam-v1'; +var urlsToCache = [ + '/', + '/index.html', + '/video.js' +]; + +self.addEventListener('install', function(event) { + 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); + } + ) + ); +}); + +self.addEventListener('activate', function(event) { + var cacheWhitelist = ['pico-cam-v1']; + event.waitUntil( + caches.keys().then(function(cacheNames) { + return Promise.all( + cacheNames.map(function(cacheName) { + if (cacheWhitelist.indexOf(cacheName) === -1) { + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); \ No newline at end of file |