Forma saysServer-Sent Events stream one-way updates from server to browser over a single long-lived HTTP connection.
When you only need the server to push to the client — live scores, notifications, log tails — Server-Sent Events (SSE) are simpler than WebSockets. The browser opens an EventSource(url); the server keeps the connection open and sends text events; your onmessage fires for each.
SSE auto-reconnects, works over plain HTTP, and is text-only. It's one-directional: for client→server you still use normal requests. Needs a server that streams text/event-stream, so it can't be fully demoed in this offline sandbox.
Power-ups you unlock
EventSource(url) opens a one-way server→client stream
Auto-reconnects; text-only; works over HTTP
Simpler than WebSockets when you only need server push
Client→server still uses ordinary requests
Captain Invalid Input attacks — common mistakes
Reaching for WebSockets when one-way SSE would do
Expecting to send data back up the EventSource (you cannot)
Server not sending the text/event-stream content type
Boss battleSketch the client: open an EventSource, log each message, and handle onerror. (Run it against a real SSE endpoint to see it stream.)
Example code
<!doctype html>
<html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px">
<pre id="out">SSE needs a streaming server. Client shape:</pre>
<script>
const out = document.getElementById('out');
// against a real text/event-stream endpoint:
// const es = new EventSource('/events');
// es.onmessage = e => out.textContent += '\n' + e.data;
// es.onerror = () => out.textContent += '\n[reconnecting…]';
out.textContent += '\n\nconst es = new EventSource("/events");\nes.onmessage = e => log(e.data);';
</script>
</body></html>