Skip to content

What is SSE

Key idea:

SSE (Server-Sent Events, EventSource API) — a standard for streaming data from server to client over plain HTTP. Client opens a GET to the endpoint with Accept: text/event-stream, the server keeps the connection open and sends messages as they are ready. Unlike WebSocket: unidirectional (server→client only), works through any HTTP proxy, native auto-reconnect, no Upgrade handshake.

Below: details, example, related terms, FAQ.

Details

  • Content-Type: text/event-stream
  • Format: data: {json}\n\n
  • event: custom event name, id: for resume after disconnect
  • Reconnection: automatic with Last-Event-ID header
  • 6 connections per-domain limit in Chrome (HTTP/1.1). HTTP/2 removes the limit

Example

const es = new EventSource('/stream');
es.onmessage = e => console.log(JSON.parse(e.data));
es.addEventListener('user-login', e => {...});

Related Terms

Learn more

Frequently Asked Questions

When to use SSE over WebSocket?

Server-only push (notifications, live feed). Simpler code, works through proxies. For chat/games you need WebSocket.

Automatic reconnect?

Yes. Browser reconnects with exponential backoff + sends <code>Last-Event-ID</code>.

HTTP/1.1 6-connection limit — a problem?

For a dashboard with 10+ SSE feeds — yes. Use a single multiplex endpoint or migrate to HTTP/2/3.