Skip to content

Instantly share code, notes, and snippets.

@tevko
Created August 11, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tevko/15401c73829801874efa48892ce67abd to your computer and use it in GitHub Desktop.
Save tevko/15401c73829801874efa48892ce67abd to your computer and use it in GitHub Desktop.
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(BB_SW_CACHE_NAME)
.then(function(cache) {
BB_urlsToCache.map(function(url) {
var request = new Request(url, {mode: 'no-cors'});
fetch(request).then(function(response) {
return caches.open(BB_SW_CACHE_NAME).then(function(c) {
return c.put(request, response);
})
})
})
})
);
});
@jakearchibald
Copy link

The promise for all the caching isn't being passed back to waitUntil, it's lost after the first .then.

self.addEventListener('install', event => {
  event.waitUntil(
    caches.open(BB_SW_CACHE_NAME).then(cache => {
      return Promise.all(
        BB_urlsToCache.map(url => {
          const request = new Request(url, {mode: 'no-cors'});
          return fetch(request).then(response => cache.put(request, response));
        })
      );
    })
  );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment