All posts
Internet Fundamentals

HTTP Caching and CDNs for the Person Paying the Bill

By

October 26, 2026

6 min read

Cache-Control decides what browsers and CDNs keep, for how long and for whom. Right, and most traffic never reaches your server. Wrong, and you either pay for every request or show one user's page to another. The directives that matter, four recipes, and what CloudFront charges when the cache misses.

Internet Fundamentals
Caching
CDN
Amazon CloudFront
HTTP

There are two kinds of cache between users and your server. A private cache is the user's browser and holds only their responses. A shared cache, such as a CDN, keeps one copy and serves it to everyone who asks for the same thing. The Cache-Control header (RFC 9111) instructs both.

The directives that matter

Directive

Meaning

max-age=N

Fresh for N seconds in any cache

s-maxage=N

Overrides max-age for shared caches only

no-cache

May be stored, but must be revalidated before each use. Not "do not cache"

no-store

Must not be stored anywhere

private

Only the browser may store it

public

Shared caches may store it, even for requests carrying an Authorization header

immutable (RFC 8246)

Will never change; the browser need not revalidate, even on reload

stale-while-revalidate=N (RFC 5861)

Once stale, may be served for N more seconds while a fresh copy is fetched in the background

Want a second opinion on this for your system?

Book a free 30-minute call. You'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.

Four recipes

Response

Cache-Control

Why

JS, CSS and images with a content hash in the file name

public, max-age=31536000, immutable

A new build makes new file names, so old ones never change

HTML that is the same for everyone

public, max-age=0, s-maxage=60, stale-while-revalidate=300

Browsers always check; the CDN absorbs traffic and refreshes in the background

API responses for a signed-in user

private, no-store

Never in a shared cache

Public data, such as a product list

public, s-maxage=30, stale-while-revalidate=120

Seconds of staleness in exchange for most requests never reaching the database

The cache key

A CDN treats two requests as the same when their cache keys match: the URL, plus whichever headers, cookies and query strings you include. Include too little and users get each other's variants. Include too much, such as every cookie and tracking parameter, and almost every request is unique, so you pay for a CDN that caches nothing.

The mistake that leaks data

A personalized response in a shared cache is shown to the next visitor. It usually happens when a CDN rule or framework caches a path that sometimes returns signed-in content. Mark anything user-specific private or no-store explicitly, and do not let a CDN cache responses that set cookies.

What a miss costs

On CloudFront pay-as-you-go, the first 1 TB of transfer and 10 million requests each month are free; then US transfer starts at $0.085 per GB and HTTPS requests at $0.0100 per 10,000. Flat-rate plans start at free and $15 a month with fixed allowances. Either way, the larger saving from a better hit rate is usually the load that never reaches your servers.

hoolco Monthly Review

Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.

As of October 26, 2026. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.