Skip to content

Commit

Permalink
take control
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Dobre committed Jan 6, 2017
1 parent ab65806 commit f14822b
Showing 1 changed file with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ var CACHE_VERSION = "<?php echo $this->cacheKey; ?>";
var CURRENT_CACHES = {
resource: 'resource-cache-v' + CACHE_VERSION
};

self.addEventListener('install', function (event) {
self.skipWaiting();
});
self.addEventListener('activate', function (event) {
var expectedCacheNames = Object.keys(CURRENT_CACHES).map(function (key) {
return CURRENT_CACHES[key];
Expand All @@ -21,36 +23,22 @@ self.addEventListener('activate', function (event) {
})
);
});

self.addEventListener('fetch', function (event) {
if (event.request.url.indexOf("theme/") !== -1){
event.respondWith(
caches.open(CURRENT_CACHES.resource).then(function (cache) {
return cache.match(event.request).then(function (response) {
if (response) {


return response;
}





return fetch(event.request.clone()).then(function (response) {


if (response.status < 400) {

cache.put(event.request, response.clone());
}

return response;
});
}).catch(function (error) {

console.error(' Error in fetch handler:', error);

throw error;
});
})
Expand Down

0 comments on commit f14822b

Please sign in to comment.