Bird
0
0

Given this Remix loader code:

medium📝 component behavior Q13 of 15
Remix - Performance
Given this Remix loader code:
export async function loader() {
  return new Response('Hello', {
    headers: { 'Cache-Control': 'max-age=10, stale-while-revalidate=30' }
  });
}

What happens when a user requests this loader after 15 seconds from the first request?
AThe cached response is served immediately, and a background update fetches a fresh response
BThe browser fetches a new response immediately, ignoring the cache
CThe cached response is served and no update happens until 40 seconds
DThe response is not cached at all
Step-by-Step Solution
Solution:
  1. Step 1: Understand max-age and stale-while-revalidate

    max-age=10 means cache is fresh for 10 seconds; stale-while-revalidate=30 allows serving stale cache up to 30 seconds while updating in background.
  2. Step 2: Apply timing to 15 seconds

    At 15 seconds, cache is stale (past 10s) but within stale-while-revalidate window (10+30=40s), so cached response is served immediately and a background fetch updates the cache.
  3. Final Answer:

    The cached response is served immediately, and a background update fetches a fresh response -> Option A
  4. Quick Check:

    max-age + stale-while-revalidate = serve stale + update [OK]
Quick Trick: After max-age, stale-while-revalidate serves stale while updating [OK]
Common Mistakes:
MISTAKES
  • Thinking cache is ignored after max-age expires
  • Assuming no background update happens
  • Confusing stale-while-revalidate with max-age

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes