Lesson 24 of 30
A Service Worker sitting in front of your network requests is only as good as the caching strategy behind it — and the right strategy depends entirely on how much staleness a given request can tolerate.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
A Service Worker uses Cache First for a content-hashed, versioned JS bundle. Why is this a safe choice for that specific asset?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
You already know what a Service Worker is and how it intercepts requests from the PWA lesson. This lesson is about the decision that actually determines whether that interception helps or hurts performance: which caching strategy a given request should use. The same intercepted request can be handled three genuinely different ways, each trading speed against freshness differently.
The same request can be routed through a Service Worker three different ways.
Picture a request for /api/user-preferences handled three different ways. Under Cache First, if it's ever been cached, the network is never even contacted — fastest possible response, but a preference changed on another device would never show up. Under Network First, the request always tries the network, so it reflects the latest state whenever the network is reachable, and only falls back to a (possibly outdated) cached copy if the request fails entirely. Under Stale-While-Revalidate, the cached preferences appear instantly, then a background fetch quietly updates the cache with whatever's actually current — so this response might be a version behind, but the next one won't be, without ever making the user wait for the network.
"How would you cache API responses in a Service Worker without serving stale data forever?" is a real, practical question, and naming the three strategies by what each actually optimizes for — instead of a vague "cache it, but also check for updates" — is the difference between an answer that sounds right and one that demonstrates you understand the speed/freshness tradeoff underneath all three.