cloudflare / templates

A collection of starter templates and examples for Cloudflare Workers and Pages
https://cloudflareworkers.com
MIT License
1k stars 638 forks source link

Very low TTFB with WordPress #39

Closed gijo-varghese closed 1 year ago

gijo-varghese commented 5 years ago

I've implemented as per the docs in the demo site https://gijovarghese.com. However, there is no much difference in TTFB

On testing, most of the locations have a TTFB of greater than 500ms. I tested it via https://tools.keycdn.com/performance?url=https://gijovarghese.com/. I tested multiple times so that it would cache in all servers

However, TTFB of another WP site which implemented page rules to cache everything have a TTFB <100ms in all around the world. See https://tools.keycdn.com/performance?url=https://coffeencoding.com/

What could be the reason?

Note: I've removed the part that checks for 'no-cache' header since most these tools send no-cache header

michaelbourne commented 5 years ago

I've noticed the same thing on the KeyCDN tools performance tester. "Cache Everything" page rule gives me insanely fast TTFB times on that test, but the workers cache setup does not. Inspecting the headers whos me there are no edge-cache headers coming from CF on the requests.

However, if I VPN into different countries and test the site with the workers setup, the proper edge-cache headers are present and the TTFB is great.

With that, I assume the KeyCDN test is bypassing the workers script somehow, but real world tests show it works.

gijo-varghese commented 5 years ago

@michaelbourne yeah, I noticed it too. Headers are not shown. But there is no way fo KeyCDN to detect whether it's coming from the worker or not right? @pmeenan any thoughts on this?

shagamemnon commented 5 years ago

@gijo-varghese — can you provide the Worker code you’re using?

gijo-varghese commented 5 years ago

@shagamemnon it's mostly the same as in https://github.com/cloudflare/worker-examples/blob/master/examples/edge-cache-html/edge-cache-html.js

But I've disabled the lines from https://github.com/cloudflare/worker-examples/blob/8affa71e494e43a2d2c2c106a9ad03f84472cc42/examples/edge-cache-html/edge-cache-html.js#L171 because KeyCDN and similar tools send a 'no-cache' headers

gijo-varghese commented 5 years ago

@shagamemnon any updates?

gijo-varghese commented 5 years ago

@michaelbourne how much TTFB are you getting? When I tested it with GTmetrix, it's still around 200-300ms, with cache hit

michaelbourne commented 5 years ago

My best was around 115ms, worst 300ms. I've never seen it under 100ms with CloudFlare, in any setup. ~100ms is a fair trade off to me for the additional benefits they offload from my server though.

gijo-varghese commented 5 years ago

yes, <100ms is more than enough. Even the cache everything rule gives <60ms in most of the locations (https://tools.keycdn.com/performance?url=https://coffeencoding.com/). Don't know what's wrong with service workers

wpsumo commented 5 years ago

@gijo-varghese Still seeing the same TTFB or have you switched on ARGO for lower TTFB?

gijo-varghese commented 5 years ago

@alriksson I've turned off Cloudflare for now

wpsumo commented 5 years ago

@gijo-varghese I see, may I ask Why? or just temporary dev mode?

gijo-varghese commented 5 years ago

@alriksson CF is lowering my TTFB. It's better to directly connect to the server

wpsumo commented 5 years ago

Okay, but it should be faster to connect to your server through CF with ARGO or when HTML is cached in the edge?

gijo-varghese commented 5 years ago

@alriksson Argo costs money, and I'm not willing to pay that for now. Also, there are a lot of troubles occurring when I cache HTML

wpsumo commented 5 years ago

I see, haven't experienced that much of troubles with cache HTML but do not have any memberships or transactional website so.

Thanks for sharing :)

gijo-varghese commented 5 years ago

@alriksson I've explained a few issues with WP here: https://wpspeedmatters.com/caching-html-pages-at-the-edge-using-cloudflare/

wpsumo commented 5 years ago

@gijo-varghese Yes correct! :)

But I understand it can cause issues depending on the need and sites, but then ARGO is an alternative for the one who want to pay. But the calculation of use is a bit off to pay all traffic not only the one fetched from the origin.

Did you use the free workers or the KV? Since KV do not flush the whole instance as long as you don't manually trigger the purge. KV is of course paid which wasn't what you were looking for.

I haven't tried ARGO myself to see the reduce in TTFB 35% is what they marketing it as.

lauragift21 commented 1 year ago

This repo has been moved over to the workers-sdk monorepo located here: https://github.com/cloudflare/workers-sdk/tree/main/templates

If you still have further issues about this, feel free to create an issue there. I will be closing this out for now.