Skip to content
Learn Netverks

Lesson

Step 56/58 97% through track

sse

Server-Sent Events

Last reviewed May 28, 2026 Content v20260528
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
advanced

This lesson

This lesson teaches Server-Sent Events—the ideas, syntax, and habits you need before moving on in HTML.

Without a solid grasp of Server-Sent Events, you will repeat mistakes in HTML exercises and on real pages or scripts.

You will apply Server-Sent Events in contexts like: Websites, hybrid apps, email templates, design systems, and CMS-driven content.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs. Also use the HTML reference desk when you need tag or attribute lookup.

When intermediate lessons feel comfortable and you are ready for production-style trade-offs.

Server-Sent Events maintain an HTTP connection where the server streams text events to the browser.

Ideal workloads

  • Live dashboards, notifications, incremental logs.
  • Simpler than WebSockets when only server→client pushes matter.

API surface

const source = new EventSource('/stream');
source.onmessage = (event) => { console.log(event.data); };

Operational concerns

  • Reconnect semantics built into EventSource.
  • Proxies/CDNs may buffer—configure timeouts accordingly.
  • Use HTTPS to prevent tampering.

Compared to WebSockets

Choose WebSockets when you need bidirectional binary chatter at low latency.

Infrastructure pitfalls

  • Reverse proxies buffering SSE—explicit flush / timeout tuning required.
  • Auth on long-lived streams: cookies vs tokens—expiration mid-stream UX.

Minimal server response headers

HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive

data: {"price":41.02}

data: heartbeat

Clients reconnect automatically; authenticate the stream endpoint like any API.

Rendered output (status region only)

Waiting for server events…

Your script updates this node when EventSource receives message events.

Important interview questions and answers

  1. Q: What does progressive enhancement mean in API-driven pages?
    A: Core tasks should work with baseline HTML first, then richer APIs enhance experience when supported.
  2. Q: Why is feature detection better than browser sniffing?
    A: It checks actual capability, avoids brittle UA assumptions, and degrades gracefully.
  3. Q: What is the first accessibility check before shipping any page?
    A: Verify keyboard-only task completion with visible focus and meaningful accessible names.

Tip: SSE is one-way server→client; WebSockets are bidirectional.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What confused you about this lesson?
  • How would you explain this to a teammate in 30 seconds?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump