- From: Marcos Cáceres <notifications@github.com>
- Date: Sun, 28 Jul 2019 22:45:01 -0700
- To: w3c/manifest <manifest@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/manifest/issues/774/515852848@github.com>
Consider, the code to do this in an SW would be something like:
```JS
self.addEventListener("fetch", ev => {
ev.respondWith(aCachedResponse(ev));
});
async function aCachedResponse(ev) {
const response = await caches.match(ev.request);
if (response) {
return response;
}
// go to network instead
try {
const netResponse = await fetch(ev.request);
if (netResponse.ok) {
return netResponse;
}
} catch (err) {
console.error(err);
}
// just return the index if all goes bad.
return await caches.match("/"); // OR 404.html
}
```
The above has the following advantages over `offline_page`, in that:
1. it already works in all browsers that already support service workers.
1. it gives the developer absolute control over the whole experience - including being easily debuggable in devtools.
1. it doesn't require any magic or violating/reinterpreting any HTTP cache semantics.
1. it doesn't introduce anything new to the spec - so less things to worry about.
I'd echo what both @reillyeon and @mgiuca have suggested - the motivation is right, but we already have a solution for this: service workers. Yeah, they are complicated and somewhat annoying, but they are what we have in the platform to do this today.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/manifest/issues/774#issuecomment-515852848
Received on Monday, 29 July 2019 05:45:23 UTC