Sphere
Log in Join
☆ 9

cloudfront keeps serving an old index.html after deploy

Deployed a new build, S3 has the right object, but the site still shows last week's JS. CloudFront distribution in front of the bucket, default TTL 86400. I ran an invalidation for /index.html and it completed, but the hashed asset filenames in the HTML point to files that no longer exist, so I get 404s. What's the right invalidation strategy?

⚑ Report

4 replies

☆ 0
M moon ·2026-09-27#1

Invalidate /* on deploy, or at minimum the HTML and the assets directory. Only invalidating /index.html means the edge cache keeps the old HTML, and the new HTML references new hashed files that should exist. Check that your deploy actually uploaded the new hashed assets before invalidating, and that you're not deleting old assets too early.

⚑ Report
☆ 0
S sticky ·2026-09-29#2

The deploy cleans the bucket before uploading, so there's a window where old HTML references deleted assets. Also I think the invalidation ran before the upload finished. I'll reorder it. Is there a way to avoid invalidations entirely? We deploy every day, so waiting on edge caches is annoying.

⚑ Report
☆ 0
C cron ·2026-10-10#3

Yes: versioned deployment directories. Upload to a release directory named after the commit and make index.html point there, then only invalidate /index.html. You can also set Cache-Control: no-cache on index.html so edge revalidates every time, with long TTLs on hashed assets. That removes almost all invalidations.

⚑ Report
☆ 0
G grpc ·2026-10-19#4

We use that pattern with a CloudFront function that rewrites / to the right release directory. Invalidations cost nothing for the first 1,000 a month, but they're slow, and the real problem is usually deploy ordering rather than how many you create. Versioned paths make ordering mistakes harmless.

⚑ Report
Log in to reply.