Lesson 2 of 30
The Frontend Practices track's own AWS lesson gets as far as 'CloudFront caches your files at the edge.' This lesson is the part that actually bites people in production: what a cache hit versus miss really costs, and the three real ways to invalidate one.
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
Why do content-hashed filenames (`main.a3f8c1.js`) avoid the need for cache invalidation entirely, rather than just making it easier?
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
CloudFront is AWS's CDN: a network of edge locations physically close to users, each holding a cached copy of your content so a request doesn't have to travel back to the origin (your S3 bucket, your API, wherever the real content lives) every time. The behavior that actually matters day to day comes down to three levers:
/static/* cached for a year, /api/* barely cached at all)./product?color=red and /product?color=blue can collide into the same cached response if query strings aren't included in the cache key, which is a real, recurring bug category.Content-hashed filenames: a new build is a new URL — nothing to invalidate, ever. The cheapest option, by construction.
main.a3f8c1.js) — the cheapest and most correct option. A new build is a new URL nothing has cached yet; the old cached file is simply never requested again and expires naturally. No invalidation call needed at all.aws cloudfront create-invalidation --paths "/index.html") — forces specific paths to be dropped immediately. Necessary for content that can't be renamed (like index.html itself, which has to keep a stable URL), but costs money past a monthly free allotment and isn't instant across every edge location worldwide.?page=2) needs its cache policy to include query strings, or every page of a paginated response can collide into one cached entry — a subtle, hard-to-reproduce bug that only shows up under real traffic./* behavior and a specific /api/* behavior can coexist, with requests matching /api/* correctly using that behavior's (probably much shorter) TTL even though /* is also a technical match."A user says they're still seeing the old version of the site after a deploy" is a real, recurring support question, and the strong answer reaches for the specific mechanism — TTL, cache key, invalidation propagation — rather than "tell them to clear their browser cache," which is very often not even where the stale copy actually lives.