CDN caching strategy for React websites that use chunks

Viewed 458

What's the best caching strategy for React websites that use chunks (code splitting)?

Before using chunks I would just cache everything for one year in CloudFront, and I would delete the old files and invalidate the cache after a new version of the website was deployed. Works great.

However, after I started using chunks I started getting problems. One common issue is that after deploying a new version of the site I delete the old files and invalidate the cache. One user is already active on the old version of the site and his version of the site tries to load a chunk that no longer exists, so the site crashes for him.

One potential solution would be to keep all old files for a month or longer, and delete all files that are older than X months during the deployment process.

Is there any better solution to this problem. Am I missing something special from the service worker that CRA (Create React App) provides? If I remember correctly it provides some kind of cache busting.

Thanks.

0 Answers
Related