40

When I navigate to a question page, I notice that up/downvotes changes appear instantly, comments and revisions notification as well.

Yet, looking at the Network tab in my Inspector shows no activity beyond initial page refresh.

How is that happening?

9
  • 12
    That's all part of live refresh which is done via web sockets. Live connection to server, no back and forth calls. Commented Jun 12, 2014 at 14:36
  • @Stijn they do, you just have to open the console before the socket gets. Commented Jun 12, 2014 at 14:37
  • 1
    @JanDvorak we see only the one request to init the socket connection but we don't see its activity. (do we?) Commented Jun 12, 2014 at 14:38
  • 1
    @JanDvorak I think it's just the initial handshake that appears?
    – user247702
    Commented Jun 12, 2014 at 14:38
  • 5
    @ShadowWizard we do. Click the socket to see all of its data frames Commented Jun 12, 2014 at 14:38
  • @JanDvorak oh, so cool! (I can swear it didn't exist in the past when I first noticed and checked it ;)) Commented Jun 12, 2014 at 14:39
  • right-clicking a frame lets you copy it out. Commented Jun 12, 2014 at 14:40
  • @Boann Out of curiosity, can you explain why and how you did this? I work on a site that makes heavy use of websockets (although we have a solid AJAX fallback). Commented Jun 13, 2014 at 15:59
  • @Boann Interesting, I didn't know Firefox made that so easy. I wonder if we handle that case. Thanks for the response! Commented Jun 13, 2014 at 18:07

1 Answer 1

42

Stack Exchange is using a web sockets connection to do all the live refresh stuff: live score, new activity, notifications, and more.

Since it's a live connection, it does not send requests back and forth between the client and the server (like AJAX is doing), so you don't see any new requests in the Network tab.

There is however an item for the websockets connection:

And when clicked you can view the internal activity, called "frames":

4
  • Any idea how is that implemented on the server-side? SignalR?
    – haim770
    Commented Jun 12, 2014 at 19:13
  • 7
    @haim770 nope, custom socket server that SE team developed themselves: meta.stackexchange.com/a/168148/152859 Commented Jun 12, 2014 at 19:49
  • 2
    Very neat stuff; one of very few websites actually incorporating WebSockets. Per actually Building this, you almost definitely have to have your Own server, as I doubt GoDaddy (I.E.) will let you fire up your server application on one of their web servers. A server application like this would be something built in an actual programming language... I would do it in C#, but it's achievable in Java, C, C++ - anything that can open a host socket on the system. Commented Jun 13, 2014 at 15:54
  • @DigitalJedi805 true, SE chose C# too since all the codebase is already written with it. Commented Jun 13, 2014 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .