Abstract


  • The server and client exchange data instantly (or near-instantly) as soon as something happens, instead of waiting for the client to refresh or poll on a schedule

๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ-๐—ฆ๐—ฒ๐—ป๐˜ ๐—˜๐˜ƒ๐—ฒ๐—ป๐˜๐˜€


  • Based HTTP, server keeps a connection open and pushes text data to the client whenever it wants. It is like a one-way webSocket

Workflow

  1. Client opens connection: new EventSource('/events')
  2. Server responds with Content-Type: text/event-stream and keeps connection alive
  3. Server pushes data in simple format: data: {"price": 142.50, "symbol": "AAPL"}
  4. Client receives events via eventSource.onmessage = (event) => { ... }

Doesn't guaranteed delivery

This is very bad for chat apps or collaborative editing.

However, it still works well for stock tickers and progress update where missing one score update doesnโ€™t matter as long as the latest value is displayed.

What if client wants to change things mid-stream?

It must use a separate HTTP request to adjust the behaviour. Thatโ€™s why for bidirectional control, people often pick WebSockets (client โ†” server messages on the same channel).

References