Reputation: 10312
There are things on Github that update almost instantly. One example is when a merged branch is pushed, it's corresponding pull request will update to a merged
status almost immediately.
I assumed this was a WebSocket, but I can't see any websockets in my devtools (or Wireshark), then I thought it might be the Push API, but don't I need to opt-in to allow that to work?
I'm asking because I'm looking for a means to push (near) realtime updates to my users within a web app, and I'm curious how Github do it.
Upvotes: 9
Views: 1213
Reputation: 45382
Github.com uses websocket for notifications, but let's see where the websocket is called
Github.com uses web workers. Specifically, for notification, they are using shared workers which is why you don't see the network activity in the network tabs of your browsing context.
In order to see shared workers, in a new tab type: "chrome://inspect/#workers", you would see something like this :
Click on inspect, and go to networks tabs :
If nothing shows up, click "terminate" and refresh your other tab page (github.com) so that it comes up again
This file (behaviors-xxxx.js) loads the workers url :
this.worker = new SharedWorker("/socket-worker.js","socket-worker-v7"),
The worker is loaded via this script: https://github.com/socket-worker.js
Upvotes: 9