Skip to content

Instantly share code, notes, and snippets.

@cmd-johnson
Last active August 20, 2019 21:54
Show Gist options
  • Save cmd-johnson/8fa0aa067126746bbf8f3b8cdbd71d55 to your computer and use it in GitHub Desktop.
Save cmd-johnson/8fa0aa067126746bbf8f3b8cdbd71d55 to your computer and use it in GitHub Desktop.
Service Worker Cache Debugging

Get single cached response

(async (cid, rid) => {
  const cacheKeys = await caches.keys();
  const cacheName = cacheKeys[cid];
  const cache = await caches.open(cacheName);
 
  const keys = await cache.keys();
  const key = keys[rid];
  console.log(cacheName, key.url);
  const cached = await cache.match(key);
  const reader = cached.body.getReader();
  let s;
  do {
    s = await reader.read();
    console.log(new TextDecoder("utf-8").decode(s.value));
  } while (!s.done);
})(1, 5).then()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment