Re: [slightlyoff/ServiceWorker] `caches.match` search order (#862)

> Shouldn't it be the expected behaviour?

No, it would break sites if V1 starts getting V2's assets. If I explicitly wanted this behaviour, I could delete the old cache, but I've never wanted that behaviour.

> If developers are afraid of breaking the page, then why don't they use Cache.match instead?

You could also do that to get the latest version.

If you really want a reverse cache search, here it is:

```js
function reverseCacheSearch(request) {
  return caches.keys().then(cacheNames => {
    return cacheNames.reverse().reduce((chain, cacheName) => {
      return chain.then(response => {
        return response || cache.open(cacheName).then(c => c.match(request));
      })
    }, Promise.resolve())
  })
}
```

In most cases, you may even get away with:

```js
caches.matchAll(request).then(r => r && r[r.length-1]);
```

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/862#issuecomment-204000116

Received on Thursday, 31 March 2016 16:02:46 UTC