Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.




okay wtf this is amazing, seems usable with websockets too.

usage of Shared Web Workers https://dev.to/ayushgp/scaling-websocket-connections-using-s...

caniuse Shared Web Workers 45% https://caniuse.com/sharedworkers

caniuse BroadcastChannel 96% https://caniuse.com/broadcastchannel


Yeah, the issue with SharedWorkers is that Android Chromium doesn't support it yet. 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_A...) rather than Broadcast Channel

This library (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.


Ultimately this is what I did. But if you need or want per-tab connection state it will get complicated in a hurry.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: