Skip to content

Stale content after a deploy behind Cloudflare: purge patterns that actually work

The deploy went out, the origin has the new build, and users are getting old CSS, broken styling, or missing JS chunks. The edge is still serving the previous build. Here is why deploys and caches fall out of sync and the pipeline order that keeps them together.

A deploy changes the origin in one atomic step, but the caches in front of it — browser, Cloudflare edge, any origin-side cache — keep serving the previous build until each one expires or is told otherwise. The result is the mixed-version page: fresh HTML pulling stale CSS, or stale HTML requesting JS chunks the deploy just deleted. Two practices end this permanently: fingerprinted asset filenames, and a purge step wired into the deploy pipeline in the right order.

What’s happening

By default Cloudflare edge-caches static extensions — exactly the files a build changes (CSS, JS, images, fonts) — and does not cache HTML. So the standard failure mode after a deploy is inverted from intuition: the HTML is fresh from the origin on every request, but the assets it references are still the old edge copies. Same URLs, old bytes: layouts break subtly or a hashed-bundle SPA refuses to boot.

The mirror-image failure happens when HTML is cached (Cache Rule, APO) or held in browsers: stale HTML requests asset URLs from the previous build. If the deploy deleted those files, users get 404s on JS chunks — the classic post-deploy ChunkLoadError flood. Both failures are versioning problems: nothing guarantees that the HTML version and asset versions a visitor receives came from the same build.

What to check first

  • Are asset filenames fingerprinted? app.3f2a1c.js changes URL every build and can never be served stale against new HTML; app.js can.
  • Does the deploy delete the previous build’s assets? Deleting old chunks at deploy time guarantees 404s for anyone holding older HTML.
  • Is there any purge step in CI at all, and does it run after the origin actually serves the new build?
  • Is HTML edge-cached on this zone? That decides whether HTML needs purging too or refreshes by itself.

How to verify

Compare the asset’s age against your deploy time:

curl -sI https://example.com/assets/app.css | grep -iE '^(cf-cache-status|age|last-modified|etag)'

HIT with an age larger than the seconds since you deployed means the edge never picked up the new build. Confirm the origin really has the new bytes — the deploy itself might be the lie:

curl -s https://example.com/assets/app.css --resolve example.com:443:203.0.113.10 | md5sum
curl -s "https://example.com/assets/app.css?fresh=$(date +%s)" | md5sum

The first hash is the origin’s copy; the second forces a new cache key through the edge and should match it. If those two match but the plain URL serves different bytes, the edge holds a stale entry — purge material. If they differ from what you shipped, the problem is the deploy or a second origin behind a load balancer still running the old build.

The fix

  1. Fingerprint every asset. Content-hashed filenames from the bundler make each build’s assets brand-new URLs: the edge fetches them on first request, and the old entries expire in place, harmless. This one change removes assets from the purge conversation entirely.

  2. Keep the previous build’s assets available. Deploy additively: upload the new build’s assets, keep at least one previous generation on disk, then flip the HTML. Visitors holding pre-deploy HTML (or a not-yet-updated service worker) keep resolving their chunks.

  3. Purge in the pipeline, after the origin flips. The order matters: build → upload assets → activate new HTML → verify origin → purge. Purging before the origin serves the new build repopulates the edge with the old content and makes the purge look broken.

    curl -sX POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
      -H "Authorization: Bearer $CF_API_TOKEN" \
      -H "Content-Type: application/json" \
      --data '{"files":["https://example.com/","https://example.com/pricing/"]}'

    Purge by URL for a known page list; Purge Everything is acceptable for small zones. Hostname, tag, and prefix purges are Enterprise options — the decision table is in Cloudflare cache purge strategies.

  4. Give edge-cached HTML a deploy story. Either purge the HTML URLs in the same pipeline step, or keep Edge TTL short (minutes) so stale windows stay small.

  5. Retire query-string busting. ?v=123 only works while the query string is in the cache key; a later normalization change silently disables it. Fingerprinted filenames do not have that failure mode.

  6. Version the service worker. If a PWA is in the stack, ship cache-name changes and cleanup on activate — a service worker pinning old assets perfectly imitates a CDN bug.

When this fix is wrong

If only a handful of users see the old build and headers show the edge serving fresh content, the stale layer is their browser cache running out a long Browser TTL — renaming assets going forward is the only cure. If the “stale” page is DYNAMIC HTML, Cloudflare never cached it: look at the origin’s page cache. And if the origin itself alternates between old and new responses, you have a half-deployed origin pool behind a load balancer, not a caching problem.

Common mistakes

  • Purging before the new build is actually live at the origin, then re-caching the old bytes.
  • Deleting the previous build’s assets in the same step that uploads the new ones.
  • Relying on ?v= busting after a cache-key change ignored query strings.
  • Running Purge Everything on a large zone at peak traffic and eating the origin refill — with Cache Reserve, also paying for the re-writes; see Tiered Cache and Cache Reserve.
  • Testing the deploy from an office machine whose browser cached the old build, and “confirming” a false failure.

Prevention

Make the pipeline own freshness: fingerprinted assets, additive uploads, origin verification, then an API purge as the final deploy step — never a human clicking after complaints arrive. Add a synthetic post-deploy check that fetches the homepage and one hashed asset and fails the pipeline on mismatch. The official cache documentation covers purge scope and limits per plan.

Deploys should end with the caches told, not the caches guessed at. Cache layers that fight each other cost real revenue — Stack Harbor tunes the whole stack, edge to origin, under Managed Cloud Ops; book an infrastructure review.