SSE, simply¶
The browser asks once. The server keeps sending updates.
That is Server-Sent Events (SSE). It uses an ordinary HTTP response that stays open, rather than a new request for every update.
Start with a live clock¶
Open http://127.0.0.1:8765. The time changes because the server sends a new value every second. The page does not refresh.
Three things to remember¶
- A stream: an HTTP response that stays open for updates.
- An event: one text update, finished by a blank line.
- EventSource: the browser's built-in JavaScript API for receiving those updates.
For example, the server sends:
tick names the update. data holds its contents. JSON is a convenient choice,
not a requirement of SSE.
A short learning path¶
- Run the demo and watch one clock.
- Understand the idea with a tiny browser example.
- Try three experiments: inspect, disconnect, reconnect.
You can stop there. You do not need stocks, chat, brokers, or deployment configuration to understand the basic idea.
When you need more¶
- Event fields:
data,event,id, andretry. - Browser API: connection handling and listeners.
- Reliability: reconnects, heartbeats, and replay.
- Server code: how the optional broadcast examples work.
- Choosing a transport: SSE, polling, or WebSockets.
- Production checklist: deployment concerns, not beginner prerequisites.
- Cheatsheet, quiz, and exercises.
Reconnect is not replay
EventSource normally retries a lost connection automatically. Recovering missed events requires the server to store and replay them. This demo sends live updates only.