-
Notifications
You must be signed in to change notification settings - Fork 124
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
Allow SDK usage from service worker #292
Comments
How could this tie in with running sync from the service worker (separate issue, not part of this)? The only way I can think off would be to:
|
So, we'll need a rollup plugin where we can define files where imports should be replaced with importScripts (in our case //... service worker constants...
import {startServiceWorker} from "./main.js";
startServiceWorker(); which will be turned into //... service worker constants...
// defines __sw_main as global variable
importScripts("sw-main-13924839.js");
const {startServiceWorker} = __sw_main;
startServiceWorker(); so we'd need to look for We'll also need to use manualChunks to set up these chunks:
|
how about code used in sdk like the observables we (might) use in app-main as well? separate chunk? |
also see https://github.com/surma/rollup-plugin-off-main-thread seems like importScripts can work with AMD modules? Could we compile the common code to AMD and also use that for loading the SDK from the document/main thread? But if not loading our main bundle with a |
Note that vite also has support for compiling web workers, but that just throws everything in an IIFE. So it won't help us with this issue really, as going that way would make the service worker huge, which is problematic as it can't be cached. |
The service worker is growing in size, so everything the browser polls for an update, it downloads the whole file. Also, the code is growing in complexity, and it is becoming hard to navigate the single large file. All the replaced variables should be defined in the file, along with an import, and the bundle with the real code should go in a file that has a content hash on it.
We want to keep the ability to run the service worker without transpilation in both latest FF and Chromium, so we need to use(can't do this anyway if we want to run sync from service worker).importScripts
We will end up using multiple files in the main import, and we would want those bundled up, so we would need to build a bundle for the service worker code that is worker-compatible (e.g. exports it symbols through a global variable) and then with the build script replace the name we do
importScripts
of in the service worker.being bundled up into
sw.js
andsw-bundle-34985934.js
. Most of the work will be in the build.mjs script, the rest in reorganizing the service worker code into multiple files.The olm worker currently isn't very big but might eventually also benefit from this.
The text was updated successfully, but these errors were encountered: