Re:I took a job at Amazon, only to leave after 10 months
by denysvitali on Wednesday January 05, 2022 @05:05PM
(#29815695)
Wow. Thanks for the explanation and for being humble in considering it (partially) your mistake.
I have to admit it was quite a plot twist, but this is why I love HN: we're both users and developers at the same time!
Re:I took a job at Amazon, only to leave after 10 months
by benadam11 on Wednesday January 05, 2022 @04:36PM
(#29815313)
Thanks for following up! Looks like that setting was on from an old version of the site. Probably not a super common thing for people who are onboarding to CF Pages (previously my origin was on AWS) and I migrated to Pages.
Re:I took a job at Amazon, only to leave after 10 months
by aghilmort on Thursday January 06, 2022 @01:04AM
(#29820032)
seconded -- great read / info also as user of Cloudflare Pages for multiple domains
Re:I took a job at Amazon, only to leave after 10 months
by SergeAx on Thursday January 06, 2022 @02:41AM
(#29820560)
Isn't that a default behavior for modern JavaScript SPAs: bundle all the frontend code into several files with unique hash names and refer them from generic html home page? Changing hash every time code changes?
Re:I took a job at Amazon, only to leave after 10 months
by geelen on Sunday January 09, 2022 @06:23PM
(#29868525)
Yes, which is why Pages has some dedicated logic to help preserve assets that were "seen in the last version now gone". Unfortunately, the "cache everything" setting at the CDN overrides that. We should probably be clearer about that in the docs, and potentially we could autodetect that setting when you register your custom domain, hmmm...
The problem is that your site generator produces different file names for each version, but doesn't preserve the old files. So when you upload a new version, then the old version of the assets become 404, unless they happened to be cached. But it's possible the HTML is cached and the CSS not cached, in which case people will get the old HTML which refers to a CSS file that is now 404.
This is a classic problem and we need to find a better way to solve it. In principle, though, you could manually avoid it by preserving older versions of the CSS such that they continue to be served under new versions of the site.
Alternatively, if you change the config on your domain so that it doesn't cache at all (or at least turn off the "cache everything" option), and instead rely on Cloudflare Pages itself to manage caching, that also should mostly* avoid the problem. Pages does do its own caching, so adding a second layer of caching on top of that shouldn't be necessary.
* There's still a problem if someone is unlucky enough to load the site exactly when it's being updated, but at least a refresh fixes that. We need a better answer, though...