AJAX & Async Requests·AJAX from first request to live updates

Polling and streaming

Choose polling, long polling or server-sent events for live data.

Beginner 13 min read Lesson 8 of 300 Challenge included
What you will be able to do
  • Poll on a sensible interval with backoff.
  • Use SSE for one-way updates.
  • Use WebSockets for two-way collaboration.
  • Cancel and reconnect deliberately.

In plain English

Polling asks repeatedly; long polling holds a request; server-sent events stream one-way messages. WebSockets are for two-way realtime. Pick the simplest model that meets the freshness requirement.

sse.jsJavaScript
const source = new EventSource('/api/events')
source.addEventListener('lesson', (event) => {
  const lesson = JSON.parse(event.data)
  console.log(lesson.title)
})
source.onerror = () => console.log('reconnecting')
Your turn

Open an event stream

Easy

Create an EventSource for /api/events.

JAVASCRIPT · starter
const source =
Check your understanding before moving on.
Knowledge checkQuestion 1

Which transport streams one-way updates from server to client?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 8 of 300 · 0% of course