[ServiceWorker] Background caching (#574)

Adding this as a placeholder for a problem we need to solve at some point.

If I'm caching a large resource I'm likely to close/hide the browser, go do something else, but still expect the cache to update. Thinking about audio/video here, but also large game assets. In these cases it's likely the ServiceWorker will be shut down and presumably caching will fail.

We need another way. Something that will let the SW shut down and open again on completion.

Eg

```js
self.addEventListener('push', function(event) {
  event.waitUntil(
    fetch('/large-audio.mp3').then(function(response) {
      if (response.status != 200) throw Error("Nahhhh");
      
      return caches.open('music').then(function(cache) {
        return cache.backgroundPut('/large-audio.mp3', response);
      });
    })
  )
});

self.addEventListener('backgroundcachesuccess', function(event) {
  event.cacheName; // 'music'
  event.request.url; // 'https://origin/large-audio.mp3'
  new Notification("New music downloaded!");
});

self.addEventListener('backgroundcachefailure', function(event) {
  // ?
});
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/574

Received on Thursday, 4 December 2014 13:44:54 UTC