4 ms·
Or a SharedWorker that creates a single SSE connection for all your tabs. SharedWorker is not very complicated but it's another component to add. It would be c
by remram 2y ago
Or a SharedWorker that creates a single SSE connection for all your tabs.
SharedWorker is not very complicated but it's another component to add. It would be cool if this was built into SSE instead.
- uncomplexity_ 2y agookay wtf this is amazing, seems usable with websockets too. usage of Shared Web Workers https://dev.to/ayushgp/scaling-websocket-connections-using-shared-workers-14mj https://dev.to/ayushgp/scaling-websocket-connections-using-s... caniuse Shared Web Workers 45% https://caniuse.com/sharedworkers https://caniuse.com/sharedworkers caniuse BroadcastChannel 96% https://caniuse.com/broadcastchannel https://caniuse.com/broadcastchannel
- nchmy 2y agoYeah, the issue with SharedWorkers is that Android Chromium doesn't support it yet. https://issues.chromium.org/issues/40290702 https://issues.chromium.org/issues/40290702 But rather than Broadcast Channel, you can also use the Web Locks API (https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_A...) rather than Broadcast Channel This library (https://github.com/pubkey/broadcast-channel/blob/master/src/leader-election.js#L307 https://github.com/pubkey/broadcast-channel/blob/master/src/...) from the fantastic RxDB javascript DB library uses WebLocks with a fallback to Broadcast Channel. But, WebLocks are supported on 96% of browsers, so probably safe to just use it exclusively now.
- hamandcheese 2y agoUltimately this is what I did. But if you need or want per-tab connection state it will get complicated in a hurry.