- From: James Browning <notifications@github.com>
- Date: Mon, 22 Feb 2021 20:46:43 -0800
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1407/783873737@github.com>
With [this pull](https://github.com/w3c/ServiceWorker/issues/1356) being merged, currently there is no way to import a module that uses TLA whatsoever.
I understand the reason is that `import()` invokes fetch and so doesn't work offline, but could we get some way to prefetch/parse modules so that the service worker can still asynchronously evaluate them? Which is to say, we declare them upfront synchronously and only those modules can be dynamically imported later:
```js
// Service worker can treat ./moduleWithTLA.js and it's subgraph as necessary for
// the service worker, so it should fetch this graph as well, the service worker would
// only become active once the graph for ./moduleWithTLA.js has successfully fetched and
// parsed, it does not however block *evaluation* of the current module
registerModule("./moduleWithTLA.js");
self.addEventListener("some-event", async (evt) => {
evt.waitUntil(async () => {
// Allowed, triggers no fetch as once this service worker is active, ./moduleWithTLA.js
// is already saved and cached with the rest of the modules
await import("./moduleWithTLA.js");
// Not allowed, this module wasn't registered, so it wasn't fetched before activating
// the service worker, as such `import()` immediately throws an error
await import("./notRegistered.js");
});
});
```
--
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/ServiceWorker/issues/1407#issuecomment-783873737
Received on Tuesday, 23 February 2021 04:46:56 UTC