Angular app breaks after deploy until the CDN cache is purged. What should I check?

November 16, 2026 4 answers
Asked by 2e+socketfunnel_641

Our production Angular app breaks after deployment, but the same build works in staging. Purging the CDN cache fixes it. The browser reports that JavaScript and CSS requests received text/html instead of the expected content types.

Could this be a stale index.html, or is there something else I should check first?

Answers

n.672~canvaskey

Start with the actual failing requests before changing cache settings. In the browser network panel, check the requested URL, status, response body, content type and cache headers for both index.html and a failed bundle. HTML in place of JS or CSS could be an error page or an SPA fallback, not an old bundle.

Compare those responses with the origin if you can, and look at CDN cache status and age headers where available. That should help narrow down whether the HTML is stale, the asset is missing, or a rewrite is returning the wrong response.

2e+socketfunnel_641:

So the MIME error tells me what came back, but not by itself which cache or rewrite caused it?

_b68+socketladle.7:

Right. The response body and the exact URL are good clues, then comparing the CDN and origin responses can narrow it down.

Reply to this answer
Velnix-6d

Check whether your production build uses content hashes in the JS and CSS filenames. If filenames stay the same between builds, a CDN can serve an older asset under the same URL. Hashed filenames let you cache bundles for a long time because changed content gets a new URL.

For index.html, use a policy that makes caches revalidate or avoid storing it, and check that the CDN follows that policy. The HTML still needs to point to the current bundle names. Purging the HTML during deployment can also help, depending on your setup.

Reply to this answer
u.859!corkwrench

Also think about tabs that are already open when you deploy. Angular can request a lazy loaded chunk later in a session. If the old hashed file was deleted, that request can fail even though the new index and bundles are fine.

Keeping previous build assets available for a while helps. How long depends on how long sessions tend to last. You can also handle a chunk load failure with a single reload, but guard against a reload loop if the problem persists.

Reply to this answer
_a38!clampfolio.6

Take a look at the SPA fallback rule too. If a missing bundle gets rewritten to index.html, the browser sees HTML where it expected a script or stylesheet. Excluding asset paths from the fallback should make missing files return a real 404, which makes this much easier to diagnose. It won't bring a deleted bundle back, though.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions