On May 9, 2023, I changed the IP that my Cloudflare site was pointing to. It has been more than a week since then, so DNS changes should have definitely propagated.
Since then, Cloudflare randomly starts to cache empty files (in the request header, these have a “content-length” of 0). Any time Cloudflare updates its cache for a file, the cached file is empty. All files that still work that existed on the site before the IP change have a “last-modified” date of before when the IP was changed, namely May 5th. All of the files that still work have a cf-cache-status of EXPIRED.
To temporarily fix the issue, you can change the query string for the file, and it will retrieve a previous version of it that Cloudflare has in its cache, which is always expired.
Here are the request headers for a working image (taken on May 17):
HTTP/2 200 OK
date: Wed, 17 May 2023 16:06:18 GMT
content-type: image/png
content-length: 1625
x-powered-by: Express
cache-control: public, max-age=14400
last-modified: Fri, 05 May 2023 21:53:32 GMT
etag: W/“659-187ede7eca8”
cf-cache-status: EXPIRED
accept-ranges: bytes
report-to: {“endpoints”:[{“url”:“https://a.nel.cloudflare.com/report/v3?s=6%2FqVtXJwbqqS%2FVA%2BF7CraYLHqmD6cph2oyuzEMqnF5LkV71CGB3IxCzXHYBLNKSXWfj8s1R9eT9swZ800f0PiyzWBMFipat6cU3UEm3ZC4Pv7efnzbNlApF6gA%3D%3D”}],“group”:“cf-nel”,“max_age”:604800}
nel: {“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: 7c8d1b602c4d1725-IAD
X-Firefox-Spdy: h2
Reloading the page still keeps the cf-cache-status EXPIRED. Note that the last-modified was before I changed where the IP for where the DNS was pointing.
For a broken image, the headers look as follows:
HTTP/2 200 OK
date: Wed, 17 May 2023 16:13:45 GMT
content-length: 0
last-modified: Wed, 17 May 2023 15:02:08 GMT
cache-control: max-age=14400
cf-cache-status: HIT
age: 20
accept-ranges: bytes
report-to: {“endpoints”:[{“url”:“https://a.nel.cloudflare.com/report/v3?s=sNaMKdT73MDaZ9BUtoWzIscVWM6rpEZmyQwznYoH1gPstfGQQQTpkARd1dmImmDpu0lpE%2FrIBNMUVAVbRGQVhEjlxR5Km5ZuB%2B%2BTxXvA9vsZ8QENH901a4Rn4%2BVedD39”}],“group”:“cf-nel”,“max_age”:604800}
nel: {“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}
vary: Accept-Encoding
server: cloudflare
cf-ray: 7c8d2646fa355a0a-IAD
alt-svc: h3=“:443”; ma=86400, h3-29=“:443”; ma=86400
X-Firefox-Spdy: h2
Purging Cloudflare cache temporarily fixes this issue, until Cloudflare starts caching these empty files again. Perhaps Cloudflare is trying to query the old IP (which is no longer online) for the static content to cache? All files that are loading that existed before the DNS change has a “last-modified” of before the DNS settings were changed. All files that existed prior to the DNS change that have a later “last-modified” date will return an empty file.
I’ve also tried creating a page rule to set the Edge TTL to be very short (2-4 hours), but that did not fix anything.
How do I fix this and have Cloudflare cache the files normally? Any help on this would be greatly appreciated!