I'm wondering how SO is able to display the "New answers have been posted" message when I'm typing an answer for a question. Does my browser send an AJAX request to the SO servers, or does SO send a trigger back to my browser?

2 Answers 2


SO can't send trigger to the browser due to the very nature of web.

SO is using AJAX indeed, here is part of the code responsible for that nice message:

var count = parseInt(data.message);
if(count > 0) {
    var msg2 = count + " new answer" + (count == 1 ? " has" : "s have") + " been posted - ";
    msg2 += '<a onclick="heartbeat.answer.update()">load new answers.</a>';
    notify.show(msg2, notifyMessageTypeId);

The server is sending back the amount of new answers and if positive, the message is displayed.

If you really want, shouldn't be too hard to find the actual code invoking the AJAX request. :)

EDIT: This is not relevant anymore due to real time updates using web sockets:
New Feature: real time updates to questions, answers, and inbox

  • Does the the browser poll the server at regular intervals ?
    – Subhra
    Jul 5, 2012 at 8:24
  • @Subhra not anymore, now it's using web sockets which is new feature and allows two way communication. Not sure what happens in case of browser not supporting it (currently only Chrome does) so I asked the developers and waiting for answer. Jul 5, 2012 at 8:38
  • Please let me know if you get the answer . I need to implement similar thing and the solution should be cross browser.
    – Subhra
    Jul 5, 2012 at 8:51
  • @Subhra so use AJAX mechanism like it was used here, it will take long time until web sockets become cross browser. Jul 5, 2012 at 9:09

The former; it sends an AJAX request to /posts/POSTID/edit-activity-heartbeat every 45 seconds or so, and gets back info like if any new answers have been posted, or if the post has been deleted (so the answer button can be grayed out)

You must log in to answer this question.

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