Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let CACHE = 'cache';
- self.addEventListener('install', function(evt) {
- console.log('The service worker is being installed.');
- evt.waitUntil(precache());
- });
- self.addEventListener('fetch', function(evt) {
- console.log('The service worker is serving the asset.');
- evt.respondWith(fromCache(evt.request));
- });
- function precache() {
- return caches.open(CACHE).then(function (cache) {
- return cache.addAll([
- '/media/wysiwyg/homepage/desktop.jpg',
- '/media/wysiwyg/homepage/bottom2_desktop.jpg'
- ]);
- });
- }
- function fromCache(request) {
- return caches.open(CACHE).then(function (cache) {
- return cache.match(request).then(function (matching) {
- return matching || Promise.reject('no-match');
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement