Best practices for persisting assets across deployments on Cloudflare Pages?

I’m reaching out to the community for advice regarding an issue I’ve encountered with Cloudflare Pages. When I deploy a new version of my Single Page Application (SPA) that utilizes code splitting, users currently accessing the site experience loading errors because the assets from the old version return a 404 not found error.

I’ve attempted to mitigate this problem by enabling Cloudflare’s Tiered Cache and Cache Reserve features, hoping to persist the cache and thereby retain the old assets for a longer period. However, I’ve hit a roadblock because the assets served by Cloudflare Pages do not include a content-length response header, even when the accept-encoding is set to identity, which is a requirement for the Cache Reserve feature to function properly.

One solution I haven’t tried yet is creating a deployment script that would upload the resources to Cloudflare R2 storage. Before I proceed with this approach, I wanted to consult the community:

  1. Are there any best practices or recommended strategies for ensuring that old version assets remain available for a certain period after a new deployment on Cloudflare Pages?
  2. Has anyone successfully implemented a solution that effectively avoids the 404 errors on assets after a new deployment, without resorting to external storage options?
  3. Is there any way to configure Cloudflare Pages or the caching system to maintain old assets even after a new version goes live?

I would greatly appreciate any insights, experiences, or advice on this matter. Ensuring a seamless user experience during updates is crucial, and I’m hoping to find the most efficient and effective way to address this challenge.

Thanks in advance!