Server-Sent Events (SSE) is a standard web technology that enables servers to push real-time updates to browser clients over a persistent HTTP connection using the text/event-stream content type. Unlike WebSockets, SSE provides unidirectional server-to-client streaming using familiar HTTP infrastructure, making it simpler to implement and deploy for scenarios like live notifications, dashboards, LLM token streaming, and progress updates. The key advantage is automatic reconnection: when a connection drops, the browser's EventSource API automatically attempts to reconnect, optionally resuming from the last event using the Last-Event-ID header. With HTTP/3 (QUIC) now prevalent, SSE benefits from eliminated head-of-line blocking and no connection limits β making it the default transport for most AI streaming APIs and real-time feeds in 2026.
What This Cheat Sheet Covers
This topic spans 15 focused tables and 121 indexed concepts, 94 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core Concepts & EventSource API
The EventSource interface is SSE's browser-native client; it abstracts connection management, event parsing, and reconnection so you only need to handle incoming events. Understanding what the API does automatically β and where it falls short β determines when to use it versus a fetch-based alternative.
| Concept | Example | Description | |
|---|---|---|---|
const es = new EventSource('/events') | β’ Browser API that opens a persistent HTTP connection and receives server-pushed events β’ handles parsing, reconnection, and event dispatching automatically. | ||
Content-Type: text/event-stream | β’ Required HTTP response header that signals SSE protocol β’ charset UTF-8 is implicit and should not be explicitly added as it can break some implementations. | ||
Browser reconnects on disconnect | β’ EventSource automatically attempts to reconnect if the connection dropsβ’ configurable via the retry field sent from server. | ||
Server β Client only | β’ SSE is server-to-client only β’ client sends regular HTTP requests if bidirectional communication is needed (contrast with WebSocket's full-duplex design). | ||
All messages must be UTF-8 text | β’ SSE exclusively supports text data encoded as UTF-8 β’ binary data requires Base64 encoding or similar text-safe transformation before transmission. | ||
es.onmessage = (e) => {...} | β’ Events are dispatched to registered listeners β’ supports both default message events and custom named event types via addEventListener(). | ||
Connection: keep-alive header | β’ Long-lived HTTP connection remains open indefinitely β’ requires server and proxy configuration to prevent premature timeout. | ||
Close SSE when tab hidden, reopen on focus | β’ fetch-event-source automatically closes the SSE connection when the document is hidden (tab minimized) and reconnects when visible againβ’ reduces unnecessary server load; opt-in behavior on native EventSource. |