EMZETT.
Login

HTTP caching

In short: HTTP caching stores responses so they do not have to be loaded from the server every time. It speeds up pages and saves data.

In more detail: The server controls caching with headers: Cache-Control (how long and by whom it may be stored), ETag and Last-Modified (checking whether something has changed). On a check, the server only answers “304 Not Modified” if nothing has changed.

In Depth

  • max-age=31536000, immutable: for files with a hash in the name: cache for a year.
  • no-store: for sensitive responses that must not be stored anywhere.
  • no-cache: storing allowed, but ask the server before every use.
  • public and private: shared caches (CDN) or only the browser.
  • stale-while-revalidate: deliver a stale response immediately and renew it in the background.
  • Source of errors: Caching HTML too long leads to outdated pages.

See also: CDN (content delivery network), Error code 304 (Not Modified)