Reference

Event stream wire format

UTF-8 text/event-stream. Normative: WHATWG parse / interpret.

One event = fields + blank line

event: balance-updated
id: 42
data: {"cents":1200}
retry: 5000

The empty line ends the event and causes dispatch. No blank line → event is not dispatched (incomplete tail is discarded at EOF).

Fields

Field Effect
data: Append value + LF to data buffer. Multiple lines → one event; trailing LF stripped before dispatch. Client sees string in event.data.
event: Event type name. Empty/default → message (onmessage). Named → addEventListener(name) only.
id: Sets last event ID. On reconnect, browser may send Last-Event-ID. Empty id field clears it.
retry: Reconnect delay in milliseconds (ASCII digits only). Hint to the UA.
: comment Line starting with : is ignored. Common keep-alive every ~15s (proxy idle timeouts).

Parsing quirks

Resume contract

// Browser reconnects with:
Last-Event-ID: 42

// Server responsibility (not automatic):
// - read header
// - emit only events after 42 (or replay policy you define)
// - keep using id: on subsequent events

Without server support, id only fills event.lastEventId — it does not invent a replay log.

Minimal server response headers

HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive