element-hq / element-hq/hydrogen-web
Allow SDK usage from service worker
- Dominant language
- TypeScript
- Stars
- 714
- Forks
- 131
- PR merge metrics
- No merged PRs in 30d
Description
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 `importScripts`~~ (can't do this anyway if we want to run sync from service worker).
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.
- service-worker/
- service-worker.js
- main.js
- push.js
- cache.js
being bundled up into `sw.js` and `sw-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.
Contributor guide
Assessment
This issue has not been assessed yet.