Skip to content

infra(cloudfront): content-hashed assets immutable for a year, loader JSON no longer edge-cached for a day - #809

Merged
thinkclay merged 1 commit into
mainfrom
fix/788-immutable-assets
Sep 17, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/788-immutable-assets

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #788. Part of #802.

The AWS change is already applied and verified (it lives in the account, not the repo); this PR records it, replaces the stale S3-era CloudFront config with the live one, and makes the deploy script assert the headers so a console edit cannot silently undo them.

What changed on CloudFront

EAS Hosting hard-codes max-age=3600 on every static asset with no override (its caching reference: "a default cache time of 3600 seconds will be applied for browser caches"; Cache-Control is honoured for API routes only). So this is a CloudFront response headers policy, on all three distributions:

behaviour (new, in precedence order) cache policy response headers
/_expo/static/* Managed-CachingOptimized scaffald-immutable-assets 260ff2ed-5e41-4d44-b320-fd767d111371 → public, max-age=31536000, immutable
/_expo/loaders/* scaffald-ssr-html (0 / 60 s / 3600, query strings in the key) + AllViewerExceptHostHeader —

Production, verified after Deployed:

/_expo/static/js/web/entry-5bc6db9f….js   cache-control: public, max-age=31536000, immutable
/_expo/static/css/global-d206bb2c….css    cache-control: public, max-age=31536000, immutable
/                                          cache-control: s-maxage=3600, must-revalidate, private, max-age=0   (unchanged)
/_expo/loaders/jobs?probe=1..3             x-cache: Miss ×3   (query string now in the key)
www.scaffald.com/_expo/static/…            301 → scaffald.com   (viewer-request function intact)

The second finding, fixed in the same edit

/_expo/loaders/* — the JSON that client-side navigation fetches for route loaders — fell under the existing /_expo/* behaviour and its CachingOptimized policy. The origin sends no Cache-Control on loader responses, so the edge kept them for that policy's 24-hour default: three consecutive fetches of /_expo/loaders/jobs returned x-cache: Hit with age 32 → 34 → 36. A client-side jump to /jobs could show a day-old listing next to a server-rendered page that was 60 s old. Loaders now use the same scaffald-ssr-html policy as the pages they belong to. This was outside #788's text; flagging it here rather than leaving it.

Dev and preview

dev.scaffald.com and preview.scaffald.com are behind their own distributions (E3J4DOM99FE5N, E1YYVZYC1XER5O) with only a default behaviour, so they got the same two behaviours in front of it — every custom domain now answers the same way, and the deploy script's assertion holds for all three targets. Only the raw *.expo.app URLs keep EAS's hour.

In the repo

  • infra/aws/cloudfront/apex-distribution-config.json — the live E1JU35IZ18YNEL config (get-distribution-config, CallerReference stripped), replacing distribution-config.json, which described the S3 + OAC pipeline deleted 2026-08-03.
  • infra/aws/cloudfront/response-headers-immutable-assets.json — the policy as created.
  • scripts/deploy-web-eas.sh — after the reachability smoke, fetches the entry bundle and the HTML and fails if the bundle is not immutable or the HTML is.
  • docs/agents/SSR-DEPLOY.md, infra/aws/README.md — behaviours, policy id, the loader finding, expected headers.

Not comparable to Lighthouse: cold-load numbers do not see repeat-visit caching, which is why this was a separate issue.

🤖 Generated with Claude Code

…d loader JSON is no longer edge-cached for a day (#788)

EAS Hosting hard-codes a one-hour browser cache on every static asset and
offers no override, so a visitor who returns after an hour re-downloaded the
whole bundle for a URL that cannot change. CloudFront is the only place to
fix that: a `/_expo/static/*` behaviour now carries the
`scaffald-immutable-assets` response headers policy
(`public, max-age=31536000, immutable`), on the prod, dev and preview
distributions. The HTML's caching is untouched.

Found while placing that behaviour: `/_expo/loaders/*` — the JSON that
client-side navigation fetches for route loaders — fell under `/_expo/*` and
its CachingOptimized policy, and because the origin sends no Cache-Control
on loader responses, the edge kept them for the policy's 24 h default. A
client-side jump to /jobs could show a day-old listing beside a server
render that was 60 s old (`x-cache: Hit`, growing `age`). Loaders now use the
same `scaffald-ssr-html` policy as the pages they belong to, query strings in
the key.

The live distribution config replaces the S3-era file that described a
pipeline deleted in August; the deploy script asserts the two headers after
every deploy so a console edit cannot silently undo this.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content-hashed assets are cached for one hour, so every repeat visitor re-downloads 17.4 MB

1 participant