Lesson 2 · Unit 04
Caches and CDNs
Cache-Control, ETags and 304s, and copies kept close to users
What you practise
Cache-Control,max-age,ETagand 304s, browser vs shared caches, CDNs and edge locations, cache busting with hashed filenames, what must never be cached
Try a question from this lesson
Pick one
A site's 200 KB logo never changes. A visitor views 30 pages, each showing the logo. What is the cheapest way to serve it?
Correct answer
Send it once and let the browser keep its copy
Why
The fastest request is the one that is never made. A stored copy costs no round trip and no bytes. The hard part is knowing when the stored copy has become wrong.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The server sets the rules
A cache is a stored copy of a response. The server says how long it may be used with a Cache-Control header.
max-age=3600 means: for the next 3,600 seconds this copy is fresh, so reuse it without asking me. The ETag is a version label for the content, used once the copy has gone stale.
HTTP/1.1 200 OK
Content-Type: image/png
Cache-Control: max-age=3600
ETag: "v42"Concept
Whose cache?
Your browser's cache serves only you. A shared cache, such as a CDN or a company proxy, serves everyone who passes through it.
private allows only the browser to keep a response. public allows shared caches too. no-store allows nobody. no-cache allows storing, but demands a check with the server before every reuse.
10 more exercises in the app
- 1× type the answer
- 4× multiple choice
- 1× fill the blanks
- 1× match the pairs
- 2× true or false
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.