Software-Engineering

Browser Caching

What is Browser Cache?

Browser cache stores static resources locally (HTML, CSS, JavaScript, images, fonts) so that repeated requests do not hit the server again.

Goal:


Why Browser Cache Matters (Engineering View)


Cache Flow (Simplified)

First Request (Cache Miss)

Browser → Server → Response + Cache Headers → Stored in Cache

Next Request (Cache Hit)

Browser → Cache → Response served (No server call)


What Gets Cached?

Do NOT cache:


Core HTTP Cache Headers (Must Know)

Cache-Control (Most Important)

Example: Cache-Control: public, max-age=3600

Common directives:


ETag (Revalidation-Based Cache)

Server sends:

Browser sends:

Server response:

Used when content changes frequently and exact version comparison is required.


Last-Modified (Time-Based Validation)

Server:

Browser:

Less accurate than ETag but still used.


Hard Cache vs Revalidation Cache

Cache Type Server Call Performance
Hard Cache (max-age valid) No Fastest
Revalidation (ETag / Last-Modified) Yes Slower

Cache Decision Logic

Request → Check cache → Is cache valid (max-age)?


API Caching (Basics)

Cache only:

Example:

Never cache:


Common Engineering Mistakes


Best Practices