Observers, workers and the platform · mid
Web Workers, Service Workers and messaging
A Web Worker runs JavaScript on another thread for heavy work (no DOM); a Service Worker is a proxy between the page and the network for offline and caching; they talk to pages with postMessage (structured clone), and tabs talk with BroadcastChannel.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Web Worker: new Worker(url); postMessage/onmessage; good for parsing, image work, heavy compute. Data is copied (structured clone) unless transferred (ArrayBuffer).
- Service Worker: install/activate/fetch lifecycle, controls pages in its scope, intercepts fetch, uses the Cache API; HTTPS only.
- Caching strategies: cache-first for static assets, network-first for API data, stale-while-revalidate for semi-fresh content.
- BroadcastChannel and the storage event sync tabs; window.postMessage talks to iframes (always check event.origin).
The red pen
Common traps: mistake → fix
Mistake: "a service worker makes code run in parallel"
Fix: that's a web worker; a service worker is a network proxy with its own lifecycle.
Mistake: "postMessage shares objects"
Fix: it copies them (structured clone) unless transferred.
Easy to hard
Questions interviewers ask, easy to hard
- Web worker vs service worker?
- How would you make an app work offline?
- How do you sync state across tabs?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.