Server-Sent Events (SSE) is the web platform’s standard way for a server to push a continuous, one-way stream of updates to a browser. It is defined in the Server-Sent Events section of the WHATWG HTML Living Standard, which specifies both a JavaScript interface, EventSource, and a wire format, text/event-stream. Where WebSocket gives full-duplex communication, SSE deliberately covers only the common case of server-to-client updates, and does so over ordinary HTTP rather than a separate protocol.
On the client, a page opens a stream by constructing an EventSource with a URL. The object exposes a readyState that moves through CONNECTING, OPEN, and CLOSED, along with event handlers: onopen fires when the connection is established, onmessage fires when data arrives, and onerror fires on failure. Calling close() ends the stream; the specification requires that doing so “must abort any instances of the fetch algorithm started for this EventSource object, and must set the readyState attribute to CLOSED.” Because EventSource is a high-level API, the browser handles the underlying connection details for the developer.
The data itself flows in a plain, line-based text format. The specification is strict about encoding, stating that “event streams in this format must always be encoded as UTF-8.” Each message is built from fields — a data field carries the payload, with multiple data lines concatenated by newlines; an event field names a custom event type; an id field records the last event identifier; and a retry field tells the client how long to wait before reconnecting. A blank line dispatches the accumulated fields as a complete event.
A defining feature of SSE is automatic reconnection. If the connection drops, the browser reconnects on its own and sends the last event id back to the server in a Last-Event-ID header, letting the server resume the stream from where the client left off. This built-in resilience, together with the simple text format, makes SSE markedly easier to adopt than a custom long-polling scheme, since it reuses standard HTTP semantics, headers, and infrastructure.
SSE found a natural niche for live feeds that flow predominantly in one direction: status notifications, news and social timelines, progress updates, and dashboards. For applications that need the client to send a steady stream of messages back, WebSocket remains the better fit, but for the large class of pure server-push use cases, SSE offers a lighter-weight, HTTP-native alternative that any web server can implement by emitting a text/event-stream response.