26

Content on the StackOverflow website often updates without refreshing the screen.

I understand it is using Ajax, so I break out my handy Firebug, and look for the GET requests on the console but there are none (other than asking for similar questions or autosave).

The timer can maybe be just a clock running on the client, but I have seen other updates such as when a new post has been added.

How do they do this?

0

2 Answers 2

28

By using websockets. In simple words, they keep a websocket connection open when you open a page and do all session data transport via it. If it cannot open/reopen the websocket connection, they resort to using the XmlHttp based AJAX (haven't checked)

I believe they do have a normal XHR based AJAX fallback option (haven't checked). Just that if your browser fully supports websockets, you'll never see the normal HTTP requests.

1
  • Sweet! Websockets. I definitely need to read up on that!
    – user1032531
    Feb 20, 2013 at 15:09
9

enter image description here

As the guy above said, Stackoverflow uses websockets, you can see in the screenshot of the same page, they have sockets for likes on question, answers, reputation everything..

Websocket is a duplex connection protocol, as HTTP is single side only, client asks server responds, but with technologies like websocket, you get an option to send data from server to client also whenever some event happens on server..

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