Created
October 5, 2018 00:42
-
-
Save sintaxi/4f0c89f61e184510d0286cec311cf107 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.addEventListener('install', function(event) { | |
event.waitUntil( | |
caches.open('v1.1').then(function(cache) { | |
return cache.addAll([ | |
'/style.css', | |
'/app.js', | |
'../views/404.html', | |
'../views/offline.html' | |
]); | |
}) | |
); | |
}); | |
this.addEventListener('fetch', function(event) { | |
event.respondWith( | |
caches.match(event.request).then(function(resp) { | |
return resp || fetch(event.request).then(function(response) { | |
if((event.request.url.includes('chrome-extension'))){ | |
//skip any caching | |
return response; | |
} | |
if (['404','0'].includes(response.status)) { | |
return caches.match('../views/404.html'); | |
} | |
return caches.open('v1.1').then(function(cache) { | |
cache.put(event.request.url, response.clone()); | |
return response; | |
}); | |
}); | |
}).catch(error => { | |
return caches.match('../views/offline.html'); | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment