Workers, Service Workers, and Offline
You will learn how to get work off the main thread and how a service worker turns a site into an offline-capable, installable app. Interviewers ask because both answer the same recurring question: what do you do when one thread is not enough?
on this pageshowhide
explore
- Dedicated Web Workers5 questions
- Worker Message Passing5 questions
- Service Worker Lifecycle6 questions
- Service Worker Caching Strategies6 questions
questions
page 2 of 2Your team wants a service worker to cache authenticated API responses in Cache Storage so the app works offline. How would you decide whether that is acceptable, and what would you require before approving it?
basics
~20 sWeigh the offline benefit against storing per-user data on disk under an origin-wide, unencrypted namespace keyed by URL. Approve it only for read data whose staleness is harmless, with per-user cache names, a hard clear on logout and account switch, and a bounded, audited entry set.
You are designing a browser feature that runs CPU-heavy work in dedicated Web Workers. How do you decide how many workers to create and whether they are long-lived or spawned per task, and what does `navigator.hardwareConcurrency` actually tell you?
basics
~20 sSize a small pool, typically hardwareConcurrency minus one and capped low, and keep it long-lived rather than spawning per task. hardwareConcurrency reports logical processors visible to the page, not free capacity — user agents may clamp it, and the main thread and other tabs are competing.
showing 31–33 of 33