Polling and streaming
Choose polling, long polling or server-sent events for live data.
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.
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
EasyOpen an event stream
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.