We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Cache Headers

Query strings are a great way to brute force cache controls as the client - but the best way (assuming you have control of the server, and c'mon, we're backend devs), is to use the Cache-Control header. Some common values are:

  • no-store: Don't cache this at all
  • max-age=3600: Cache this for 1 hour (3600 seconds)
  • stale-while-revalidate: Serve stale content while revalidating the cache
  • no-cache: Does not mean "don't cache this". It means "cache this, but revalidate it before serving it again"

The fact that no-cache means "lol jk you can actually cache this just check with me first" makes me feel some sort of way

You can view all the other options here if you're interested.

When the server sends Cache-Control headers, it's up to the browser to respect them, but most modern browsers do.

Assignment

Let's do things the right way and control caching with headers from the server.

Run and submit the CLI tests.

Reassigning an image's existing src may not trigger a request, even with caching disabled. That's image loading behavior, not a failure of no-store.