Advertisement
Guest User

Untitled

a guest
Nov 6th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let CACHE = 'cache';
  2.  
  3. self.addEventListener('install', function(evt) {
  4.     console.log('The service worker is being installed.');
  5.     evt.waitUntil(precache());
  6. });
  7.  
  8. self.addEventListener('fetch', function(evt) {
  9.     console.log('The service worker is serving the asset.');
  10.     evt.respondWith(fromCache(evt.request));
  11. });
  12. function precache() {
  13.     return caches.open(CACHE).then(function (cache) {
  14.         return cache.addAll([
  15.             '/media/wysiwyg/homepage/desktop.jpg',
  16.             '/media/wysiwyg/homepage/bottom2_desktop.jpg'
  17.         ]);
  18.     });
  19. }
  20. function fromCache(request) {
  21.     return caches.open(CACHE).then(function (cache) {
  22.         return cache.match(request).then(function (matching) {
  23.             return matching || Promise.reject('no-match');
  24.         });
  25.     });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement