0Pricing
Frontend Academy · Lesson

Server-Sent Events for One-Way Streaming

Use EventSource to receive a stream of server-sent events, parse event types and data, and reconnect automatically on network interruptions.

What Are Server-Sent Events?

SSE is a standard HTTP-based protocol for the server to push events to the browser over a single long-lived connection. One-way: server → client only. Simpler than WebSockets when you don't need to send back.

EventSource API

The browser's EventSource connects to a URL and listens for events. Standard, built-in, no library needed.

const es = new EventSource('/api/events');

es.addEventListener('message', (event) => {
  console.log('Received:', event.data);
});

es.addEventListener('error', () => {
  console.error('Connection error');
});

All lessons in this course

  1. WebSocket API: open message close error
  2. Socket.io Client Integration
  3. Server-Sent Events for One-Way Streaming
  4. Real-time UI Patterns
← Back to Frontend Academy