Settings

Theme

Speeding Up Your Website Using Cloudflare Cache

pillser.com

83 points by lilouartz 2 years ago · 25 comments

Reader

pbowyer 2 years ago

> Serve Stale Content While Revalidating (Not Working as Expected)

> This is the only thing that I was not able to figure out.

For good reason, because (at the last time I tried this earlier this year) Cloudflare documents stale-while-revalidate as if it's supported [1], but it isn't [2], [3].

Cloudflare instead has a different behaviour [4], [5] which helps in some circumstances but not all.

I use Fastly's free CDN plan to get round this.

1. https://developers.cloudflare.com/cache/concepts/revalidatio...

2. https://community.cloudflare.com/t/support-for-stale-while-r...

3. https://community.cloudflare.com/t/when-will-cloudflare-full...

4. https://kerkour.com/cloudflare-stale-while-revalidate

5. https://stackoverflow.com/questions/48124415/does-cloudflare...

  • lilouartzOP 2 years ago

    Ended up ditching Cloudflare for this use case https://pillser.com/engineering/2024-08-26-speeding-up-your-...

  • bosch_mind 2 years ago

    Fastly is trash and nowhere near as good as CF.

    • Beijinger 2 years ago

      I think CF is trash, at least in the free version.

      Why you should never use Cloudflare. It causes problems, is bad for SEO and a Spyware tool.

      https://expatcircle.com/cms/why-you-should-never-use-cloudfl...

      If it is free, then you are the product. If you need a CDN, there are cheap solutions out there. And Pics should always be delivered from your domain, not from CF.

      • brookst 2 years ago

        > If it is free, then you are the product

        I use Linux and it’s free. Am I the product?

        • Beijinger 2 years ago

          Good point. But Linux is not a for-profit enterprise. Sex is free too. At least it is better when it is free.

          • fragmede 2 years ago

            For the buyer or the seller? The buyer has no incentive to make it good for the seller. The seller has every incentive to make it good for the buyer.

            How much experience buying and selling it and getting it to free do you have to make that claim? Can you link to any peer reviewed studies?

      • otherme123 2 years ago

        CF doesn't use you as the product, a la Facebook, Instagram or Google. They try to lure you in with the free tier, and then upsell.

        That's a bussiness model that you might like or not, but almost everyone is doing that one way or the other (first X months are free, free tiers, free Comunity Editions, etc.)

    • pbowyer 2 years ago

      Fastly's product is not trash.

      Fastly's ability to sensibly price their product, market their product, and stop losing money hand over fist is trash.

      And I write this as someone who has been snubbed by Fastly multiple times.

      Squashed between Akamai and Cloudflare, I will be sorry to see them go.

    • aetimmes 2 years ago

      Care to explain why?

turtlebits 2 years ago

Before adding complexity, try to make your web sites smaller!

I'm not a big fan of adding more complexity (infra and money) to improve performance.

  • GenerocUsername 2 years ago

    Cloudflare and other cdn caches are a pretty standard web technology. Literally storing files closer to the client and serving it from hardware specializing in fast static serving

    • jsheard 2 years ago

      Yeah, there's no getting around physics when moving data over a long distance. Even in the absolute best case scenario if you ran a single uninterrupted fiber optic cable half way around the world it would still take about 100ms for light to cross it (fiber isn't quite as fast as the speed of light in a vacuum), and it's only downhill from there with realistic networking and protocol handshakes slowing things down.

      • 10000truths 2 years ago

        You can't get around the laws of physics, but you can control the number of round trips necessary to render your website. With HTTP/3, you can deliver data to a client after just one RTT, and a 200-250 ms time-to-first-byte is still plenty fast for a CRUD app.

  • ksec 2 years ago

    Both CDN and DNS should really be standard sort of practice. Simply because we cant beat speed of light.

    The problem is modern day CDN do many clever things it is easy to go wrong.

  • SushiHippie 2 years ago

    Agreed, for example I have a ping of 200ms to Hacker News, and the last time I checked it still runs on a single core, and yet there was never a moment where I wished that Hacker News would be faster.

    (Sometimes Hacker News gets fronted by Cloudflare when there is too much spam, but it's not the default)

  • onion2k 2 years ago

    Size isn't the only consideration though. Latency is pretty much a fixed cost for web resources, and caching is very beneficial if your edge cache is closer to the user than the origin server (and it is, unless you're very unlucky).

  • victorbjorklund 2 years ago

    of course always better to make the code more efficient. But honestly it isnt very complex to have a CDN for static content

arghwhat 2 years ago

To use the cache you shouldn’t need to do any of this - just have appropriate cache headers.

daviding 2 years ago

Some rough cost numbers of using this would be nice.

  • freitasm 2 years ago

    With the exception of Cache Reserves, all these features are free.

    Cache Reserve pricing is based on storage usage but optional.

    • arghwhat 2 years ago

      Caching is free up until a service ceiling - certain file types and sizes are excluded in the free tier for example.

j45 2 years ago

Cloudflares free cache is pretty good as well.

Also have heard things like jscompress to reduce the number of calls on loading a page can go a long way too to boost speed.

wetimeai 2 years ago

is is a quick fix. and for smaller websites i recommend it. However it has its limits and it can frustrate when you are developing. But in general yeah good free service.

taw1285 2 years ago

does this approach make sense for an app-router based nextjs app hosted on vercel?

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection