Sean
Sean
CDCloudflare Developers
Created by Sean on 3/4/2025 in #pages-help
Caching issue with Custom Domain for preview branches
We followed this guide: https://developers.cloudflare.com/pages/how-to/custom-branch-aliases/ Setup Preview Branches: dev & staging Production branch: prod - we have set this under our Workers & Pages / <pages name> / Settings - we are not using git integration. We have CI pipelines that use wrangler pages deploy along with --branch and --commit-hash to ensure we push to the appropriate CD Branch. For our 3 environment names we have custom domain assigned - each custom domain is a hostname we use Cloud Flare to manage our DNS for. Following the instructions, we created the custom domain from our workers and pages app. Then for the preview branches, we went to our DNS records and updated the target to be dev.<page-name>.pages.dev and staging.<page-name>.pages.dev. - As per the CF documentation we have left them proxied:
Currently, this setup is only supported when using Cloudflare DNS. If you attempt to follow this guide using an external DNS provider, your custom alias will be sent to the production branch of your Pages project.
Our custom domains look like: - app.<domain> -> prod (CF branch name) - app-dev.<domain> -> dev - app-staging.<domain> -> staging Problem On our preview sites (app-dev.<domain> and app-staging.<domain>) we have noticed that cloudflare is returning inconsistent files. Most of the time it returns the correct file deployed to environment branch. - Sometimes the file request returns with 404 status when a file only exists on the preview branch but has not made it to prod - Sometimes the file request returns the prod version of the file instead of the dev or staging version. For example one of our bundle files is statically named: service-worker.js. And we have a unique identifier inside of it per release which allows us to confirm we're getting the prod file when we should be getting the preview version. We've tried: - purging cache (everything) - cache rules to bypass everything
3 replies