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, 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. SSE works seamlessly with HTTP/2 multiplexing, eliminating the historical 6-connection-per-domain limitation that affected HTTP/1.1, and requires no special proxy configuration beyond disabling response buffering.
What This Cheat Sheet Covers
This topic spans 14 focused tables and 100 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Concepts & EventSource API
| 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. | |
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. | |
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). |