Something is caching my Pages site

Hello, I have an issue where pages seem to be cached for some reason. I believe I have turned off Cloudflare's caching in the dashboard (see image). However, old pages are sometimes served. I have a server-side rendered page with a countdown on it. Often, what will happen is that a user will load the page, then close it, then come back to it later, and it displays the (now outdated) same server-side rendered countdown as it did the first time they visited (until JS loads and executes). This issue also happens whenever I make a change to any JS logic. I use SvelteKit, so all files are hashed (e.g., script.7010ddca.js), so caching should not be an issue. However, the actual html is cached, so it references the previous JS files, which should no longer exist but are also cached. Oddly, using ctrl+shift+r will sometimes correctly fetch the new page, but it also sometimes doesn't. I have 0 page rules, and the cache rule shown below is the only one. Any ideas about what might be causing this?
No description
7 Replies
JustinNoel
JustinNoel10mo ago
That's how I'm avoiding caching my development branches and it's working fine.
check your return headers to make sure you're not getting a max age or cashing information on them. If you're still getting 304s, then something is wrong.
ajgeiss0702
ajgeiss070210mo ago
The html response aren’t 304s, they’re just regular 200 responses that are outdated
JustinNoel
JustinNoel10mo ago
where is the countdown information coming from? Is it a database? Maybe KV? Perhaps that is what is being cashed somewhere?
ajgeiss0702
ajgeiss070210mo ago
Nope. It just counts down until a certain time every week. No DBs or external requests involved there
CiabbataConda
CiabbataConda10mo ago
could you maybe give more info? maybe the sveltekit config, the endpoint code, or even a full reproducible example?
ajgeiss0702
ajgeiss070210mo ago
I believe I have fixed it by setting the Cache-Control header
if(event.url.pathname === "/") {
response.headers.set("Cache-Control", "no-store, max-age=0");
}
if(event.url.pathname === "/") {
response.headers.set("Cache-Control", "no-store, max-age=0");
}
i40west
i40west10mo ago
It sounds like browser cache rather than Cloudflare cache. In the dashboard under Caching -> Configuration, you can set Browser Cache TTL. Probably the best setting if using Pages is "Respect Existing Headers".