Very low TTFB with WordPress on service Workers

I’ve implemented Edge cache HTML with workers in WordPress in a demo site 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 it multiple times so that it would cache in all servers. No luck

However, TTFB of another WP site which implemented ‘cache everything page rule’ have a TTFB <50-70ms 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 request header

Related GitHub issue: https://github [dot] com/Cloudflare/worker-examples/issues/39

I’m seeing the same thing. I generally use the KV setup, but I turned that off to use API instead and that didn’t change anything. I’m no longer seeing any headers indicating this worker is active. I used to get a x-HTML-Edge-Cache response header, and I’m not seeing it in yours, either. Maybe @pmeenan has some ideas.

I just read the documentation a bit more closely and see that server-side caching can interfere with this. I usually run WPFastestCache, so I disabled it. The good news is that the header is showing up. The bad news is that TTFB hasn’t decreased.

x-html-edge-cache: cache,bypass-cookies=wp-|wordpress|comment_|woocommerce_

I’m still playing around with this. I think the KeyCDN test sends a Disable Cache, so that’s not going to work. But when I play with my browser’s Dev Tools without setting Disable Cache, I do get more helpful headers:

x-html-edge-cache-status: Miss, Cached
This is on a basic site, and I’ve not yet gotten it to give me a Hit. UPDATE: After a ton of tries, I finally got a Hit. UPDATE2: Doing a force reload went back to Miss.

x-html-edge-cache-status: Hit
This on a more complex site, but it’s hitting the cache.

One thing I do see is in the above Hit, I also get the cf-cache-status header (HIT). When it’s a Miss, I don’t get the cf-cache-status header.

sigh
This is black magic. I can get a HIT for your site, but it’s not fast (576 ms) on the first load. Second time around it’s really quick. Wait a while, it’s a HIT, but slow again. So…I get the feeling it’s sorta working.

In case you’re wondering, Bypass On Cookie for Cache Everything in the Business Plan looks to behave the same way.

UPDATE (since I can’t post more than three in a row):
So I’ve had time to toy with it a bit more with more consistent results…as long as I did the following:

  1. Not use a caching plugin in WordPress.
  2. Use Firefox in Private Mode.
  3. Un-check “Disable Cache” in Firefox’s Dev Tools
  4. API vs KV doesn’t seem to have any effect on the results. Both work correctly.

With all that, I can get HITs in the response headers. It’s still not double-digit fast, though. I think that’s as good as I’m going to get for now.

1 Like

Thanks @sdayman. Even on testing locally with dev tools, if you don’t open the site for a while and open it, the TTFB is still too high (even on cache hit). I doubt it’s the boot up time of service workers

But still not idea why it’s not working on KeyCDN’s tool. Results on https://performance.sucuri.net/ is also not that different!

1 Like

If it’s something above 300ms, I would prefer to turn off Cloudflare and connect to server directly. It’s giving much better results, even from half way around the globe

1 Like