3 ms·
> Quick tip for those using static (jekyll, hugo...) sites on s3: If you have cloudflare in front of it, you can turn on aggressive html caching > If you're fa
by seanwilson 9y ago
> Quick tip for those using static (jekyll, hugo...) sites on s3: If you have cloudflare in front of it, you can turn on aggressive html caching
> If you're fancy you can even programmatically purge the cache when you do CI deploys using the cloudflare API.
You need to be really careful with this.
I'm not sure how you've got things set up but isn't this going to lead to issues unless you have a cache busting or revalidation strategy? You can purge Cloudflare's cache but that's not going to purge the cache on browsers that already visited your site and cached a page already. You might get cases where an old cached HTML page is asking for page resources that don't exist anymore or pages break because the user is seeing the old HTML with the new CSS/JavaScript.
Also, if you can log in to your site, it can potentially cache one user's logged in page content and share it with others if your Cache-Control settings don't include "private".
You could set things up to make sure the browser and then the Cloudflare cache always asks your server first if a page has been updated recently (revalidation) but your server has to be configured right for this (e.g. etag or modified date usage).
Cloudflare is actually meant to have a feature that keeps a static version of your site to show in the event of outages:
https://www.cloudflare.com/always-online/ https://www.cloudflare.com/always-online/
- scrollaway 9y agoUnfortunately afaik Always Online does not work in the event of S3 errors because S3 is available, merely answering with HTTP error codes.
- seanwilson 9y agoHmm, can you explain further? What kind of error code? So Always Online only kicks in when there's no response and not e.g. 500 error codes?
- scrollaway 9y agoCorrect, AFAIK Always Online kicks in when the upstream cannot be reached (eg. connection timeout, unreachable dns etc).
- elithrar 9y agoYou're both sort-of correct. AO kicks in on specific 5xx error codes: 502, 504, and then Cloudflare's 52x codes. It doesn't kick in on 500 or 503, or 4xx errors. Ref: https://support.cloudflare.com/hc/en-us/articles/202238800-Why-is-Always-Online-not-working- https://support.cloudflare.com/hc/en-us/articles/202238800-W...