Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/65885140/why-github-use-sharedworker-for-websocket

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...