Here’s the scenario: you delete a file from your Cloudflare Pages project, deploy your changes, double-check the repo like a hawk… and yet the file is still there.
Why? Well, Network Caching of course.
Cloudflare Pages aggressively caches files. That includes old files from previous deployments, even ones you explicitly removed. If those files were part of a past deploy, they might stick around in edge caches for hours, days, or even a week.
Even worse, those files can be accessed directly by URL. So if someone bookmarked a now-deleted file? Or if it was indexed by search engines? Or linked on social? Boom. It’s still serving. Still public. Still causing headaches.
It sounds too ridiculous to be true, but it is:
If a request is made for a file that does not exist, but existed in the previous deployment, and Pages happens to still have that file cached, it will serve it up. It won’t stick around forever but it could be a week or more.
The Headless Hostman relies on a complex infrastructure ultimate serving on Cloudflare Static. So we found more recently this was becoming an issue for our sites and customers.
Sure, these steps technically work but often times do not.
We’ve tried clearing cache from the Cloudflare-managed DNS and it doesn’t reliable solve this problem.
We weren’t okay with this. If you remove a file from your project and push a new build, that file should be gone. Period.
So we built our own 404 system.
Now, when a file disappears from your latest deployment, Headless Hostman automatically intercepts requests to that file and returns a proper 404 instantly. This is done from the Network Edge, so it doesn’t slow down your site load.
Even if Cloudflare’s cache still holds onto the file behind the scenes, it’ll never be served again.
Unless, of course, you republish the page.
This is key. If you happen to re-publish a page, we recheck it on every push:
Since Cloudflare only hangs onto stale cache for up to a week, we assign a date stamp in the 404 log.
If it’s been more than seven days, we remove the page from our 404 log. This because Cloudflare will no longer serve it on its own by this point, and because we want to keep the log as lightweight as possible.
Let’s say that instead of serving a 404 you want to 301 Redirect.
Any 301 Redirect will supersede our 404 tracker.
Another Static Problem solved by the Headless Hostman.