diff --git a/serviceWorker.js b/serviceWorker.js index 7aa1495..7299600 100644 --- a/serviceWorker.js +++ b/serviceWorker.js @@ -18,19 +18,26 @@ var APP_DATA_URLS = [ 'data/articles.json', ]; +var APP_CACHES = [ { + name: APP_DATA_CACHE, + urls: APP_DATA_URLS + },{ + name: APP_SHELL_CACHE, + urls: APP_SHELL_URLS + } + +] + self.addEventListener('install', function(event){ - event.waitUntil( - caches.open(APP_SHELL_CACHE) - .then(function(cache){ - console.log("[Cache] opened: ", APP_SHELL_CACHE); - return cache.addAll(APP_SHELL_URLS); - }) - .open(APP_DATA_CACHE) - .then(function(cache){ - console.log("[Cache] opened: ", APP_DATA_CACHE); - return cache.addAll(APP_DATA_URLS); - }) - ); + event.waitUntil(Promise.all( + APP_CACHES.map(function (myCache){ + return caches.open(myCache.name) + .then(function (cache){ + console.log("[Cache] opened: ", myCache.name); + return caches.addAll(myCache.urls); + }); + }) + )) }); self.addEventListener('fetch', function(event){