Dedicated vs Shared vs Service Workers compared
Browser worker types and roles.
Dedicated worker serves one page for offloading CPU; Shared worker is one instance across same-origin contexts via ports; Service worker is a network proxy for caching and push, event-driven and killable.
WHAT THIS TESTS Whether you understand that these three share the worker model but differ sharply in scope, lifecycle, communication, and intended purpose, and that none can touch the DOM directly.
A GOOD ANSWER COVERS A dedicated Web Worker is owned by the single script that created it; its purpose is offloading CPU-intensive work, like parsing or image processing, off the main thread to keep the UI responsive. It lives as long as its owner keeps it and communicates by postMessage and onmessage. A Shared Worker is a single instance shared by all same-origin browsing contexts, such as multiple tabs of one site; pages connect through a MessagePort exposed on the port property, making it useful for coordinating state or a single socket across tabs. A Service Worker is fundamentally different: it is a programmable network proxy sitting between the page and the network, enabling offline support via the Cache API, push notifications, and background sync. It is event-driven, registered against a scope path, has no owning page, and the browser freely starts and terminates it, so it must not hold long-lived in-memory state.
COMMON WRONG ANSWERS Claiming any worker can manipulate the DOM. Treating a Service Worker as a general compute offloader. Thinking a dedicated worker is shared across tabs. Forgetting that Service Workers are killed and revived and cannot rely on memory. Confusing the messaging models.
LIKELY FOLLOW-UPS Why must a Service Worker be served over HTTPS? How does the fetch event let it intercept requests? What is the install and activate lifecycle? Why use a Shared Worker over BroadcastChannel?
ONE CONCRETE EXAMPLE A photo app runs Gaussian blur in a dedicated worker so the slider stays smooth. It opens a single WebSocket inside a Shared Worker so five open tabs reuse one connection instead of five. It registers a Service Worker that intercepts fetch events to serve a cached app shell offline and shows push notifications, surviving across page reloads because the browser revives it on demand.
Read the original → developer.mozilla.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.