Skip to content
BENIBIX Learn

Server-Sent Events (SSE)

Development🌐 Web DevelopmentReal-Time

Also known as SSE, EventSource, Event Stream

A server sends updates to the browser. They go one way, over plain HTTP.

Think of it like

Think of it like a radio. The station keeps sending, and you just listen.

Example

Lucy's order page listens with SSE. When the parcel ships, the server sends one line, and the status changes on screen.

Why it matters

When only the server needs to talk, SSE is simpler than a WebSocket. It also reconnects for free.

Definition

Server-sent events let a server push updates to the browser. They flow over one web request that stays open. Unlike a WebSocket, messages go only one way, from server to browser. The browser listens with a built-in tool called EventSource, which reconnects on its own. Each message is plain text that starts with data:. It suits live scores, progress bars and AI answers that stream in.

Example code

javascript
const source = new EventSource("/updates");
source.onmessage = (event) => console.log(event.data);
Listen for each update the server sends to /updates.

Common mistake

Using it when the browser must also send often. Then a WebSocket is the better fit.

Key takeaways

  1. 1
    One way. Server to browser only.
  2. 2
    Plain HTTP. Works through most networks.
  3. 3
    Reconnects itself. EventSource retries for you.

Compare