We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
EventSource: The under appreciated sibling of WebSockets – Benedicte Emilie Brækken - NDC Oslo 2024
Learn why EventSource is a powerful alternative to WebSockets for real-time communication. Explore its simplicity, native browser support, and scalability benefits for server-to-client data.
-
EventSource/Server-Sent Events (SSE) is a simpler alternative to WebSockets for one-way server-to-client real-time communication
-
EventSource has better scalability than polling since it maintains a single open connection and doesn’t require constant new requests
-
Main EventSource advantages:
- Built-in reconnection handling
- Native browser support
- Works over regular HTTP
- Simple implementation
- Event parsing handled by browser
-
WebSockets create a completely new protocol connection, while EventSource uses standard HTTP
-
Key differences between WebSocket and EventSource:
- WebSocket is bidirectional, EventSource is one-way (server to client)
- WebSocket requires special server infrastructure
- EventSource works with standard HTTP servers
- WebSocket has more complex implementation
-
HTTP/2 improvements like multiplexing and server push make EventSource more efficient
-
For one-way server-to-client communication, EventSource is often a better choice than WebSocket due to simplicity
-
EventSource limitations:
- Can’t send client-to-server data (one-way only)
- Limited header customization
- No binary data support
-
Implementation requires only ~20 lines of JavaScript on both client and server sides
-
Works well with distributed systems since it uses standard HTTP infrastructure