diff options
author | Jake Archibald <jaffathecake@gmail.com> | 2015-11-16 23:54:19 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-11-16 23:54:57 +0100 |
commit | 6112adeacecb29fc378d2861d0428c26a2761147 (patch) | |
tree | 2d8ffc2e99cb5b324e1b91195d7a20b9fb59fe01 | |
parent | 59da7ea2b4bcdb9f599eefa15a7da4623df28620 (diff) | |
download | hesla-6112adeacecb29fc378d2861d0428c26a2761147.tar.gz |
Replaced the service worker implementation by the one by Jake Archibald.
-rw-r--r-- | sworker.js | 95 |
1 files changed, 47 insertions, 48 deletions
@@ -1,54 +1,53 @@ -console.log('I AM ALIVE!!!'); - -this.addEventListener('install', function(ev) { - console.log('AND I INSTALLED!!!1'); - ev.waitUntil( - caches.open("v1").then(function(cache) { - return cache.addAll([ - 'index.html', - 'activePage.js', - 'activePage.js.map', - 'config.js', - 'config.js.map', - 'hesla.js', - 'hesla.js.map', - 'hesla.webapp', - 'require.js', - 'favicon.ico', - 'icon-128.png', - 'icon-30.png', - 'icon-60.png', - 'index_de.html', - 'index.html', - 'require.js', - 'screen.css' - ]); - }) - ); -}); - -this.addEventListener('fetch', function(event) { - event.respondWith( - caches.match(event.request).then(function(pro) { - console.log('Fullfilling ' + event.request.url + ' from cache'); - return pro; - }).catch(function() { - console.log('Loading ' + event.request.url); - return fetch(event.request); - }) +var version = 'v2 - 2011-11-16'; +var toCache = [ + '/', + 'index.html', + 'activePage.js', + 'activePage.js.map', + 'config.js', + 'config.js.map', + 'hesla.js', + 'hesla.js.map', + 'hesla.webapp', + 'require.js', + 'favicon.ico', + 'icon-128.png', + 'icon-30.png', + 'icon-60.png', + 'index_de.html', + 'index.html', + 'require.js', + 'screen.css' +]; + +self.addEventListener('install', event => { + event.waitUntil( + caches.open('static' + version).then(c => c.addAll(toCache)) ); }); -this.addEventListener('activate', function(event) { - var cacheWhitelist = ['v1']; - +self.addEventListener('activate', event => { event.waitUntil( - caches.keys().then(function(keyList) { - return Promise.all(keyList.map(function(key) { - if (cacheWhitelist.indexOf(key) === -1) { - return caches.delete(keyList[i]); - } - })); - }) + Promise.all( + caches.keys().then(keys => + keys.filter(key => key != 'static' + version).map(key => caches.delete(key)) + ) + ) ); }); + +self.addEventListener('fetch', event => { + event.respondWith(caches.match(event.request)); +}); + +// this.addEventListener('fetch', function(event) { +// event.respondWith( +// caches.match(event.request).then(function(pro) { +// console.log('Fullfilling ' + event.request.url + ' from cache'); +// return pro; +// }).catch(function() { +// console.log('Loading ' + event.request.url); +// return fetch(event.request); +// }) +// ); +// }); |