-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a method to cache the URLs of all open clients #368
Comments
I'm going to bump down this priority, since it's new functionality that would be nice to have, but not needed for parity with our legacy offerings. |
Quick hack for how this might work. It would be code that run in the context of async function populateCache(cacheName) {
const urls = performance.getEntriesByType('resource').map(resource => resource.name);
const cache = await caches.open(cacheName);
return Promise.all(urls.map(async url => {
// Explicitly check to see if the URL is present in any cache, not just in cacheName.
// Otherwise, we'd end up double-caching URLs that are managed via precaching.
const alreadyCached = await caches.match(url);
if (!alreadyCached) {
try {
await cache.add(url);
} catch (error) {
// Super-hacky.
try {
const response = await fetch(new Request(url, {mode: 'no-cors'}));
await cache.put(url, response);
} catch (anotherError) {
console.info(anotherError);
}
}
}
}));
} Problems with this strawman approach:
|
Related discussion in the service worker specification: w3c/ServiceWorker#1282 |
This is now doable in v4 via a recipe that uses |
Library Affected:
sw-lib
Issue or Feature Request Description:
Add a method to cache the URLs of all open clients
This allows a dev to ensure a site can run offline after the first pageload without having to wait for a subsequent pageload.
Note: we'll probably want to make sure we use the
includeUncontrolled
optionThe text was updated successfully, but these errors were encountered: