Two Cloudflare Pages behaviours I had to measure to believe
I run a static browser-games site on Cloudflare Pages: about 4,700 prerendered HTML files, a small React shell, no server. Two things cost me days because the platform did not fail loudly. Both are easy to reproduce, so here are the measurements rather than opinions. 1. Cache-Control in _headers is ignored for static assets The symptom: after a deploy, one page said the catalogue had 211 games…
Two Cloudflare Pages behaviors proved challenging to comprehend. The first issue involves the Cache-Control in _headers being disregarded for static assets. After deploying a new version, different pages displayed varying counts of games, indicating stale content. Adding a Cache-Control rule did not resolve the issue, as the platform silently applied its own Cache-Control settings for static files.
The solution lies in incorporating content hashes in the URL, ensuring the HTML files are updated with new versions upon deployment. Another obstacle pertains to the _redirects rule limit. Despite the documentation suggesting a limit of 2,000 static and 100 dynamic redirects, the actual limit appears to be around 100 rules. Any rules added beyond this threshold are disregarded, leading to unintended consequences.
To mitigate this issue, it is advisable to keep the _redirects file under 100 rules, with the most critical rules listed first. Regular monitoring of the _redirects file using a single curl -sI command after each deployment can help ensure all rules are being properly applied. Additionally, it is crucial to verify the deletion of stale pages to avoid lingering responses.
This can be done through a simple cache-buster test. The writer emphasizes the importance of thoroughly testing the _redirects file, as a single deleted page can still return a 200 response for up to a week, potentially misleading developers into believing a deployment has failed.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.