How does HTTP caching work with Cache-Control and ETag?
Assesses fundamental understanding of Caching Strategies conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
HTTP caching lets browsers and proxies reuse responses. Cache-Control sets the policy:
max-age=300: fresh for 300 seconds; no revalidation needed.s-maxage: overridesmax-agefor shared caches such as CDNs.privatevspublic: whether shared caches may store it. Never mark personalized responsespublic.no-store: do not cache at all;no-cache: store but always revalidate.stale-while-revalidateandimmutable: serve stale while refreshing, or never revalidate a fingerprinted asset.
ETag enables conditional requests: the client sends If-None-Match, and the server replies 304 Not Modified with no body if unchanged, saving bandwidth.
ETag: "abc123"
If-None-Match: "abc123" -> 304 Not Modified
Use content-hashed filenames with long immutable cache times for static assets, and short, revalidated caching for HTML and dynamic data. Vary correctly when responses depend on headers such as Accept-Encoding.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.