Course contentsShow
← Web Development
Lesson 2394 of 2,98243. Service Workers Deep DiveFree lesson

Choosing the Right Strategy per Resource

Mapping different caching strategies to resource types based on update frequency and importance.

Choosing the Right Strategy per Resource

You'll learn how to match caching strategies to different resource types based on their update frequency and criticality.

Now that you know the different caching strategies (Cache-First, Network-First, Stale-While-Revalidate, etc.), the real challenge is deciding which strategy to use for each resource. Not all assets are created equal—your app shell needs different treatment than a news article or user profile photo.

Think Like a Resource Categorizer

Consider three key factors for each resource:

1. Update Frequency: How often does this resource change? Your logo rarely changes (months/years), but API data might change every minute.

2. Importance: Can the app function without it? Core CSS is critical; a footer badge image isn't.

3. Size/Cost: Large images waste bandwidth if fetched unnecessarily; small JSON responses are cheap to re-fetch.

Common Mapping Patterns

  • App Shell (HTML, core CSS/JS): Cache-First — these rarely change and are essential for the app to render.
  • User-generated content (avatars, uploaded images): Cache-First — once uploaded, they're immutable (or use versioned URLs).
  • API data (feeds, user profiles): Network-First or Stale-While-Revalidate — needs to be current but should have offline fallback.
  • Third-party assets (fonts, libraries from CDNs): Cache-First with long expiration — they're versioned and don't change.
  • Analytics/tracking scripts: Network-Only — not critical, and old data is worthless.

Think of it like stocking a kitchen: flour and oil (app shell) stay in the pantry long-term, milk (API data) gets checked for freshness regularly, and fresh herbs (analytics) you only use if available today.

Key Takeaway: Match caching strategies to resource characteristics—static, critical assets get Cache-First; dynamic, important data gets Network-First or Stale-While-Revalidate; non-critical resources can go Network-Only.