StoicBuilder

HandbookXIII the AqueductCDNs and edge caching

XIIIthe Aqueduct, Scale it

CDNs and edge caching

1 min readUpdated 28 November

In plain words

A CDN keeps copies of your responses in data centres around the world, so visitors get them from somewhere nearby, and your Cache-Control headers decide what may be stored and for how long.

Where you see it

Harbor's marketing pages, docs and build assets go through Cloudflare. A visitor in Sydney gets the pricing page from a Sydney data centre instead of from Harbor's servers in Virginia, and the cf-cache-status response header says HIT or MISS.

Response headersserver
# hashed build files never change: cache for a yearCache-Control: public, max-age=31536000, immutable # pricing page: the CDN keeps it 5 minutes, then refreshes in the backgroundCache-Control: public, s-maxage=300, stale-while-revalidate=60 # account and billing pages: never in a shared cacheCache-Control: private, no-store
Three kinds of response, three rules. The header you set is what the CDN obeys, unless a CDN rule overrides it.

What goes wrong

  1. Caching a page with someone's account on it

    If a signed-in response is cached as public, the CDN can hand one customer's billing page to the next visitor. Mark personal responses private or no-store, and check that no CDN rule overrides that.

  2. Long cache times on files whose names never change

    An app.js cached for a year means visitors keep the old code after a deploy. Long lifetimes are only safe for files with a content hash in their name; HTML should be short-lived or revalidated.

  3. Purging everything as the plan

    Purging the whole CDN after every change throws away every cached file at once and sends a burst of traffic to your servers. Use short lifetimes with stale-while-revalidate, or purge only the URLs or tags that changed.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
List the Cache-Control header for every kind of response we serve: hashed assets, HTML pages, public API responses and anything personal. Set hashed assets to a year and immutable, keep public pages short-lived with stale-while-revalidate, mark every signed-in or personal response private, no-store, and add a test that checks those headers.

Quick check

Sign in to earn +10 XP for it

After a deploy, some Harbor visitors get a broken page: new HTML loading an old app.js from the CDN. What's the lasting fix?

Got a prompt that touches CDNs and edge caching?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.