Cache Then Network Strategy
What you'll learn: How to deliver instant responses from cache while simultaneously fetching fresh data in the background to keep your UI up-to-date.
The Core Idea
The Cache Then Network strategy is like checking your pantry for dinner ingredients while simultaneously ordering fresh groceries for delivery. You use what you have immediately (cached resources), but you're also getting fresh supplies (network response) to update your meal as soon as they arrive.
Unlike Stale-While-Revalidate (which only updates the cache for next time), Cache Then Network updates the current page as soon as the network responds. The user sees cached content instantly, then sees it refresh with live data moments later.
How It Works
This strategy requires coordination between your page JavaScript and Service Worker:
- Page requests resource → triggers both cache lookup AND network fetch
- Service Worker returns cached version immediately (if available)
- Network response arrives → page JavaScript updates the UI and cache gets updated
Think of it like a news app: you see yesterday's headlines instantly from cache, then watch them update with breaking news as the network responds.
Best Use Cases
- Dynamic content that changes frequently (social feeds, news, stock prices)
- Dashboard data where seeing something immediately beats waiting for perfection
- User-generated content where freshness matters but speed is critical
The tradeoff? Your page code becomes more complex because it must handle two responses: the cached one and the network one. You're essentially racing the cache against the network, displaying both results in sequence.
Key Takeaway: Cache Then Network delivers instant perceived performance by showing cached content immediately while fetching fresh data to update the live UI, making it perfect for dynamic, frequently-changing content.