Caching & TOO_MANY_REDIRECTS on Next.js project deployed with Cloudflare Pages

Hi everyone, I’m running a Next.js project on Cloudflare Pages and from time to time, after a new deployment, I get TOO_MANY_REDIRECTS errors when accessing certain pages. The issue seems to be tied to JavaScript resources. What I’ve noticed: After deployment, some JavaScript file hashes change (as expected). However, the HTML page served appears to be cached with old references to JS files that no longer exist. This leads to broken requests / redirect loops until I manually purge the cache. After a purge, everything works fine—until the next deployment. This makes me think the problem is related to how HTML and asset caching is configured. Questions: Is there a recommended cache configuration for Cloudflare Pages + Next.js to avoid serving stale HTML that references outdated JS files? Should I be setting custom cache-control headers (e.g., no-cache for HTML but immutable for static assets)? Is there a Cloudflare Pages setting I’m missing that handles cache invalidation automatically after deployments? Any guidance or examples of proper caching strategies for Next.js on Cloudflare Pages would be super helpful. Thanks!
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?