EventSource

EventSource is a new HTML5 API specified in the WHATWG draft on Server Sent Events.

Server Sent Events

EventSource works by sending a stream of text based events over a normal HTTP connection that never closes.

The event-stream format used to send the messages is extremely simple and the javascript API is easy to use.

EventSource is designed to handle network problems well and to fall back to traditional long-polling gracefully.

The server maintains a buffer of events and if the event-stream connection gets disconnected the browser will retry it with an added "Last-Event-Id" header that the server can use to play back any lost events.

This makes Server Sent events a very reliable delivery mechanism.

The EventStream Format

HTTP/1.1 200 OK
Content-Type: text/event-stream

data: This is an event

event: notification
data: This is a notification

id: 12345
data: This is an event with an id

data: Multiline event
data: Line 2