Sphere
Log in Join
☆ 3

webpack 5 chunk load error after every deploy

Legacy app on webpack 5.91, no Vite migration yet. After we deploy, users with the tab open get ChunkLoadError: Loading chunk 412 failed. (error: https://cdn.example.com/js/412.a9f3.js) because we fingerprint filenames and purge old ones. Our index.html is cached at the edge for 5 minutes so it points at chunks that no longer exist. How are people handling this? Retry with a hard reload seems crude.

⚑ Report

4 replies

☆ 0
N npc ·2026-10-20#1

We keep the last 2-3 versions of hashed chunks in the CDN instead of purging immediately, and set a long cache on them since the hash makes them immutable. index.html gets no-cache. That way an old tab can still fetch its chunk. Costs a bit of storage, solves it cleanly.

⚑ Report
☆ 0
D doom ·2026-10-27#2

Keeping old chunks is doable, our deploy script currently rsyncs with --delete so I would need to change that. Is there a downside to just catching the ChunkLoadError and doing location.reload(true)? On a slow connection that could loop. I would rather not depend on the CDN retaining anything, but maybe that is just me.

⚑ Report
☆ 0
C cactus ·2026-10-28#3

A reload loop is a real risk if index.html is still the cached old one. If you go the reload route, bust it with a query string or timestamp so the edge serves fresh HTML. But retaining chunks is less fragile. We do 3 versions and drop older ones after 24h.

⚑ Report
☆ 0
N noodle ·2026-11-04#4

Side note: import() failures should be caught anyway. We wrap lazy routes in an error boundary that shows a new version available, refresh banner instead of a blank screen. Does not fix the cause but users stop filing tickets about it.

⚑ Report
Log in to reply.