Skip to content

Instantly share code, notes, and snippets.

@jeffposnick
Created December 2, 2018 17:39
Show Gist options
  • Save jeffposnick/14d84fed45713587866a34b689a51ecd to your computer and use it in GitHub Desktop.
Save jeffposnick/14d84fed45713587866a34b689a51ecd to your computer and use it in GitHub Desktop.
Code to find all opaque responses currently cached, and return their URLs.
async function findOpaqueResponses() {
const cacheNames = await caches.keys();
const urlsResultingInAnOpaqueResponse = [];
for (const cacheName of cacheNames) {
const cache = await caches.open(cacheName);
const requests = await cache.keys();
for (const request of requests) {
const response = await cache.match(request);
if (response.status === 0) {
urlsResultingInAnOpaqueResponse.push(request.url);
}
}
}
return urlsResultingInAnOpaqueResponse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment