Search code examples
socketsgithubwebsocketworkershared-worker

Why GitHub use SharedWorker for WebSocket


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?


Solution

  • 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).