Loading...

Server-Sent Events (SSE) in HTML

Server-Sent Events (SSE) technology allows the server to continuously send data to the browser without the client having to make repeated requests.

What Is SSE?

SSE (Server-Sent Events) is a one-way communication channel in which the server sends events to the browser via HTTP. It’s particularly useful for displaying live data such as weather updates, stock prices, or notifications.

Client-Side Usage

In the browser, the 'EventSource' object is used to receive events. The 'onmessage' event handler is triggered each time the server sends a new message.

Server-Side Example

The server must respond with the 'text/event-stream' content type and continuously send data in the correct SSE format. In a Node.js example, the current date is sent every second.

Advantages

- Simpler than WebSocket in many cases - Automatic reconnection if the connection drops - Great for read-only data (e.g., dashboards, alerts)

Limitations

SSE only supports one-way communication (server ➝ client), may be unreliable behind some proxies, and is sensitive to mobile networks. For high-load or bidirectional applications, WebSocket or another technology is recommended.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.


Top tools

CodeHubBoardly NEWLinksy NEWChromo NEW

Select Language

Set theme

© 2025 ReadyTools. All rights reserved.