This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Sharing IPFS node across browsing contexts (tabs) on same origin #3022
Closed
Description
When site with origin e.g. foo.com
uses JS-IPFS, new node is bootstrapped for every browser context (tab, iframe) this implies:
- All the network connections need to be reestablished.
- General memory / CPU overhead is multiplied by number of browsing contexts.
- Create a possibility for race condition (two nodes read / write data concurrently).
There is an opportunity to improve this by offloading most of JS-IPFS work into SharedWorker
in browsers where API is available and fallback to a dedicated Worker
elsewhere (basically Safari).
We can explore
ServiceWorker
as a better fallback mechanism in the future. Unilke dedicated worker they can be shared, but they also come with enough challenges to justify keeping it out of scope initially.
However use of SharedWorker
implies some trade-offs:
Worker script distribution
Worker needs to be instantiated with a separate JS script. Which leaves us with the following options:
- Create a separate "worker" dist as opt-in for shared node. That still has two more options:
- Spit out two scripts on for main context and other for worker context.
- Use something like a worker-loader to bundle worker script as a blob embedded in the the main script.
- Self load main script into worker and context detect to choose between main and worker operational modes.
Lack of WebRTC in workers
This is a major problem as WebRTC is largely replacing WebSocket transport and requires more research. Pragmatic approach could be to tunnel WebRTC traffic into a worker, however that would still imply reestablishing existing connections which would be a major drawback.