Preserve previous build artifacts when using manual uploads
We currently build our Vite static app and push the build assets using the Wrangler CLI in GitHub actions. We build it ourselves because there are some special build parameters and processes we use that aren't supported by CF Pages.
However, when we push a new release, all previous build chunk files are cleared out, causing the application to break for users on page when attempting to load routes using the JS chunks. This doesn't happen if CF Pages is the one to build it, in those situations CF Pages does keep the old assets around for an undertmined length of time.
2 Replies
This doc seems to indicate that it would preserve the old assets in a cache, but that isn't happening for us: https://developers.cloudflare.com/pages/configuration/serving-pages/#asset-retention
Cloudflare Docs
Serving Pages · Cloudflare Pages docs
Cloudflare Pages includes a number of defaults for serving your Pages sites. This page details some of those decisions, so you can understand how Pages works, and how you might want to override some of the default behaviors.
I ended up solving this by implementing build caching on the GitHub action workflow. The downside is that it means the cache will grow large over time (unless I add some way to prune it automatically), and it means sending more assets than necessary over the wire to CF pages.
I'm sure there's some way to improve it by making it only cache the previous build, but this works for now.