Frontend Developer interview question

How do browser caching strategies work?

Browser caching is controlled by HTTP cache directives and validators. Immutable versioned assets can be cached for a long time, while HTML or API data needs a policy that balances freshness, validation, and offline behaviour.

Direct answer

What a strong answer covers

How it works

HTTP caching has two independent decisions: how long a response may be reused without asking the server, set by max-age or s-maxage, and how the cache checks whether a stale copy is still valid, done with ETag or Last-Modified and a conditional request. Versioned static assets can be treated as immutable because a change produces a new URL; documents whose URL never changes need short freshness plus validation. Service workers add a programmable layer on top with their own strategies.

Example

Serve hashed JS with long max-age and immutable; serve the HTML shell with revalidation so it can point to the next asset version. An API response that changes per user needs Cache-Control: private with no-store or a short max-age, otherwise a shared CDN cache can serve one user’s data to another.

Common mistakes

  • Caching HTML for a long time so users keep loading assets that no longer exist.
  • Confusing no-cache, which allows storing but requires revalidation, with no-store.
  • Forgetting Vary when the same URL returns different bodies by Accept-Encoding or cookie.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Frontend Developer interview questions