Skip to main content

HTTP Cache-Control and Expires

· One min read
  • Cache-Control override Expires

  • Cache-Control supersedes Expires

  • Cache-Control offers more flexibility and options than Expires

  • Cache-Control use relative amount of time (seconds)

    Cache-Control: max-age=3600
  • Expires use date format

    Expires: Thu, 01 Dec 1994 16:00:00 GMT

Cache states

Caches have 2 states:

  • fresh: if cache age < max-age, the cache is valid
  • stale: if cache age > max-age, the cache needs to be validated

Validate cache when reuse

Browser will always validate cache when reuse

  • If browser has a fresh cache, it will reuse it and will not send request to server
Cache-Control: no-cache

Disable cache

Browser will not store cache

Cache-Control: no-store

Clear cache

  • Pressing Ctrl + F5 in browser will reload current page without using cache
  • Most browsers support pressing Ctrl + Shift + Delete to clear cache