change to multiple caches
This commit is contained in:
parent
62ae5335d8
commit
6dfe4e44b6
@ -18,19 +18,26 @@ var APP_DATA_URLS = [
|
|||||||
'data/articles.json',
|
'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){
|
self.addEventListener('install', function(event){
|
||||||
event.waitUntil(
|
event.waitUntil(Promise.all(
|
||||||
caches.open(APP_SHELL_CACHE)
|
APP_CACHES.map(function (myCache){
|
||||||
.then(function(cache){
|
return caches.open(myCache.name)
|
||||||
console.log("[Cache] opened: ", APP_SHELL_CACHE);
|
.then(function (cache){
|
||||||
return cache.addAll(APP_SHELL_URLS);
|
console.log("[Cache] opened: ", myCache.name);
|
||||||
|
return caches.addAll(myCache.urls);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.open(APP_DATA_CACHE)
|
))
|
||||||
.then(function(cache){
|
|
||||||
console.log("[Cache] opened: ", APP_DATA_CACHE);
|
|
||||||
return cache.addAll(APP_DATA_URLS);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', function(event){
|
self.addEventListener('fetch', function(event){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user