Other meanings of Server-Sent Events
Web Technology
Server-sent events (SSE) is a web technology that enables a server to push updates to a client over a single HTTP connection. Unlike WebSockets, SSE is unidirectional—data flows only from server to client—and is built on standard HTTP, making it simple to implement and automatically compatible with proxies and firewalls. The technology is standardized by the WHATWG as part of the HTML specification and is supported by all major browsers.
Server-sent events work by keeping an HTTP connection open and sending data in a specific text format. The client initiates the connection using the EventSource API, which automatically reconnects if the connection drops and tracks the last event ID to resume from where it left off. The server sends a Content-Type: text/event-stream header and then streams lines of data. Each event can have an id, event type, data payload, and optional retry timeout. The client listens for these events via JavaScript event handlers, such as onmessage or addEventListener for custom event names.
SSE is often compared to WebSockets and long polling. Unlike WebSockets, which provide full-duplex communication, SSE is one-way and simpler, requiring no special server libraries or protocol upgrades. It automatically handles reconnection and event IDs, reducing client-side complexity. Long polling, an older technique, repeatedly opens new connections, whereas SSE maintains a single persistent connection, reducing overhead. However, SSE has limitations: it is not suitable for bidirectional communication, and it may be limited by browser connection limits (typically six per domain) and proxy buffering. For applications like live news feeds, stock tickers, or social media timelines, SSE is often more efficient than polling and easier to implement than WebSockets.
One lesser-known feature is the Last-Event-ID header, which allows the server to resume the stream from a specific point after a reconnection, ensuring no messages are lost. Another is the ability to send named events, enabling the server to trigger different client-side handlers. SSE also supports cross-origin requests with credentials, though this requires careful configuration. Historically, the concept was first proposed by Ian Hickson in 2004 as part of the Web Applications 1.0 specification, later adopted by WHATWG. Some implementations, such as those in Node.js, use the text/event-stream format with chunked transfer encoding. Additionally, SSE can be used with HTTP/2, which allows multiplexing multiple streams over a single connection, mitigating the browser connection limit.
SSE is widely used in applications that require real-time updates without the complexity of WebSockets. Examples include live sports scores, stock market tickers, social media feeds, and system monitoring dashboards. Many server-side frameworks, such as Spring (Java), Express (Node.js), and Django (Python), provide built-in support or libraries for SSE. Cloud services like AWS and Azure offer managed SSE endpoints for event streaming. The technology is also used in machine learning for streaming model predictions and in IoT for pushing sensor data. Despite the rise of WebSockets, SSE remains a robust choice for one-way push scenarios, especially when simplicity and reliability are priorities.
SSE is a lightweight alternative to WebSockets for one-way server-to-client communication.
Help improve the encyclopedia. Reports go straight to the site manager.