SSE (Server-Sent Events, EventSource API) — a standard for streaming data from server to client over plain HTTP. Client opens a GET to the endpoint with Accept: text/event-stream, the server keeps the connection open and sends messages as they are ready. Unlike WebSocket: unidirectional (server→client only), works through any HTTP proxy, native auto-reconnect, no Upgrade handshake.
Below: details, example, related terms, FAQ.
Free online tool — HTTP header checker: instant results, no signup.
data: {json}\n\nLast-Event-ID headerconst es = new EventSource('/stream');
es.onmessage = e => console.log(JSON.parse(e.data));
es.addEventListener('user-login', e => {...});Implementing Server-Sent Events (SSE) in your web application is straightforward. Below are the steps to set up a basic SSE server and client.
In a Node.js environment, you can create an SSE endpoint as follows:
const express = require('express');
const app = express();
app.get('/events', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
setInterval(() => {
const data = JSON.stringify({ message: 'Hello from server!' });
res.write(`data: ${data}\n\n`);
}, 1000);
});
app.listen(3000, () => {
console.log('SSE server running on http://localhost:3000/events');
});To receive events on the client side, use the EventSource API:
const eventSource = new EventSource('/events');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data.message);
};With this setup, your server will send messages to the client every second, demonstrating a basic implementation of SSE.
Server-Sent Events (SSE) offer several advantages compared to other real-time data transmission technologies such as WebSockets and long polling.
These advantages make SSE an excellent choice for applications like live notifications, news feeds, and real-time updates where server-push functionality is required.
Server-Sent Events (SSE) are particularly well-suited for a variety of real-time applications. Here are some common use cases:
These use cases demonstrate the versatility and effectiveness of SSE in delivering real-time data to users efficiently and reliably.
Server-only push (notifications, live feed). Simpler code, works through proxies. For chat/games you need WebSocket.
Yes. Browser reconnects with exponential backoff + sends <code>Last-Event-ID</code>.
For a dashboard with 10+ SSE feeds — yes. Use a single multiplex endpoint or migrate to HTTP/2/3.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.