Skip to content
Back to Path
Module 9 of 18

Cache-Control Header

The Cache-Control header is the "Remote Control" for caching. The server uses it to tell the browser exactly how long to keep a file and when to throw it away.

Interactive Protocol Simulation
Step 1 / 2

Step 1 of 2

CACHE
HIT
Cache Hit
Data found locally. Ultra fast.

Syntax

Cache-Control: directive, max-age=seconds

Worked example

Response

Cache-Control: public, max-age=31536000

The value 31536000 is one year in seconds. This is common for files that never change, like a specific version of a logo or CSS file.

Common Directives

You can combine multiple directives to get the exact behavior you want:

  • max-age — The time in seconds the file is considered "fresh" (e.g., 3600 for one hour).
  • no-store — Do not save this file EVER. Use for sensitive data like bank info.
  • no-cache — You can save it, but you MUST ask the server if it changed before using it.
  • public / private — Tells shared caches (CDNs) if they are allowed to store it or if it's just for the user.

Study kit

Module 9 of 18

Intermediate · 3 min · 0 of 18 complete

Module status

Not completed yet

Notessaved locally+

Notes stay in this browser. They are not uploaded.

Suggest an edit

Discussion

0 comments

Loading discussion…

Sign in to ask a question.