12

In a previous question regarding how auto drafts are saved, waffles indicated that the draft is sent to the server during the heartbeat.

That said, the questions are:

  • How often is the heartbeat sent?
  • What is sent to the server?
  • What is received from the server?

I've been able to gather the following:

What's missing?

2

2 Answers 2

23

In the usual case (meaning you're using only one editor and not several, e.g. because you're answering a question while also editing it and another answer etc.) -- the heartbeat happens every 45 seconds.

It sends the following:

  • Whether you're writing a question, an answer, or are editing a post
  • When answering, it sends the Id of the question you're answering. When editing, it sends the Id of the post that's being edited.
  • When answering, it sends information about what other answers the client (i.e. your browser) already knows about (see below)
  • If you're asking or answering, and you have changed something since the previous heartbeat, it sends the full text of the post (and, if applicable, title and tags)

The server saves the draft, and returns the following to the client:

  • When asking, it returns a list of "similar questions" that's shown in the sidebar
  • When answering, it checks whether the question has been deleted, locked, or closed in the meantime (you have certainly seen the "this post has been closed; no more answers will be accepted" message before – this is where it comes from)
  • When answering, it checks whether there are answers that the client doesn't know about yet (see above), so you get the "2 new answers have been posted" message
  • When editing, it checks whether the post has been locked or deleted, or has been edited in the meantime ("This post has been edited 1 time since you began").

Random trivia: The heartbeat is controlled by an object called StackExchange.cardiologist.

2
  • 11
    Thanks for very detailed answer! I assume you call the error handler "HeartAttack"? ;) Commented Nov 10, 2011 at 9:53
  • 3
    @balpha: StackExchange.cardiologist is a pretty GDLK name.
    – casperOne
    Commented Nov 10, 2011 at 12:20
-1

The heartbeat is sent about once a minute, according to the very question you linked to.

You must log in to answer this question.

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