Home
← All questions

Service Workers and caching strategies | Web Fundamentals

HardPremiumWeb Fundamentals

Asked at Google · Microsoft · Spotify

Web Fundamentals interview practice: Explain service worker lifecycle and cache-first vs network-first patterns.

Answer

A Service Worker is a proxy script between the page and network, enabling offline support, push notifications, and custom caching. Runs on a separate thread; communicates via postMessage.

Lifecycle: register → install (precache) → activate (cleanup old caches) → fetch events.

Caching strategies:

StrategyUse case
Cache-firstStatic assets (fonts, icons)
Network-firstAPI data, always-fresh HTML
Stale-while-revalidateAvatars, non-critical JSON
Network-onlyPayments, auth endpoints
Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium