Why GitHub use SharedWorker for WebSocket

381 Views Asked by At

I got curious how GitHub rerender components when issue updated and found they use WebSocket in SharedWorker.
But why do they use it inside of SharedWorker, not in main thread? What's the main benefit from using WebSocket with one more thread?

1

There are 1 best solutions below

0
On BEST ANSWER

Usually, you create a WebSocket connection within a SharedWorker when you want multiple tabs or windows of the same browser instance to be able to share that connection. So, if you open multiple tabs on the same site (in this case, GitHub), one single WebSocket connection will be enough for them all.

For example, we use this technique in the client API we provide for our own WebSocket server (ConnectionSharing object).