Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Wordpress + CF Worker #41

Closed
willstocks opened this issue Aug 2, 2019 · 13 comments
Closed

Wordpress + CF Worker #41

willstocks opened this issue Aug 2, 2019 · 13 comments

Comments

@willstocks
Copy link

Hello!

So I just setup a CF Worker using the provided example (see here) and kept everything exactly as-is out of the box.

I am having to use the API config, as I don't have an option for KV storage at the moment (via the Workers tab, or workers.dev)

Workers KV is currently not available for workers.dev.

I'm noticing that most of my requests (https://willstocks.co.uk) are getting the following response headers applied:

x-html-edge-cache-status: Hit, Refreshed
x-html-edge-cache-version: -1

But if I look in my Workers stats, I'm seeing requests coming in (both cached and uncached (for the pages that I'm visiting for the first time since implementation)):
image

The x-html-edge-cache-version never increments up, despite the fact that I have the plugin installed on my WP site. I'm also not seeing the x-HTML-Edge-Cache header for some reason?

Worth noting, I am also using W3TC on my site, but I'm seeing the headers change on refresh/consecutive visits.

Any ideas? 😁

@willstocks
Copy link
Author

Also, I noticed that wordpress_test_cookie can also resulting in bypassing of the worker cache

@pmeenan
Copy link
Contributor

pmeenan commented Aug 2, 2019

I can explain parts of it anyway....

The worker serves the cached HTML immediately and then asynchronously updates the cached version from the origin when it doesn't see the headers from the plugin. That way if the plugin isn't installed and purge isn't working it will still stay up to date. That's what "Hit, Refreshed" refers to. This is likely because of W3TC which serves the HTML from disk directly from the web server and never gets a chance to add the header (which is also why you don't see it). If you are sure the plugin is installed and purging you can disable the code here.

-1 is normal for the version number when KV isn't used and it doesn't change. It is only used with KV.

As far as the worker stats go for subrequests, that's not unexpected if it is refreshing the cahced items. The main dashboard should have a view of the cache hit rate for the top-level requests.

@willstocks
Copy link
Author

OK, that makes sense! :)

So the plugin is 100% installed and activated on my site... is there a clear and simple way to verify that it is actually doing what it should be doing? In terms of the W3TC page caching, I'm currently using APCu (not Disk) for the page caching:
image

OK, good to know on the -1 front! I'm assuming (although the Cloudflare documentation is a bit inconsistent at the moment) that KV does not come along with the free plan (of which I'm currently using) and requires the paid for workers as a minimum. Some documentation says it's included, other documentation says it's not.

As a slight side note/to clarify - do I also need a page rule applied, to allow for full/optimal functionality or can that now be completely ignored as is replaced in its entirety by the worker (which takes in to account the cookies)?
image

@pmeenan
Copy link
Contributor

pmeenan commented Aug 2, 2019 via email

@willstocks
Copy link
Author

Thanks @pmeenan! Updated Page Rule and have applied, will monitor from there as well :)

As an aside, I will log a ticket with the guys at W3TC to see if they can add some form of support for this implementation.

One final question (slightly off topic!), my site runs a service-worker (network first) - is there anything that needs to be included within that so that everything runs perfectly alongside the CF Worker?

@pmeenan
Copy link
Contributor

pmeenan commented Aug 2, 2019 via email

@willstocks
Copy link
Author

Thanks @pmeenan - is it worthwhile me disabling W3TC Page Caching (only, object, database and browser would still remain) in place of the provided plugin?

@pmeenan
Copy link
Contributor

pmeenan commented Aug 2, 2019 via email

@willstocks
Copy link
Author

Have disabled W3TC cache and now I'm seeing the following on my home page consistently.

x-html-edge-cache: cache,bypass-cookies=wp-|wordpress|comment_|woocommerce_
x-html-edge-cache-status: Miss
x-html-edge-cache-version: -1

I have just cleared the comment cookies (because I was making sure pages wouldn't cache with comment form data) and I'm still seeing the same on the home page, but now not on the individual post pages (x-html-edge-cache-status: miss, cached) and then hit on next visit

@willstocks
Copy link
Author

@pmeenan
Copy link
Contributor

pmeenan commented Aug 2, 2019 via email

@willstocks
Copy link
Author

willstocks commented Aug 5, 2019

Great news @pmeenan - one of the guys from Cloudflare (CC: @signalnerve) reached out to W3TC as well on the support req. I logged 😁 Very exciting stuff here!!!

As an aside... any idea on why I might just see a straight up "miss" response for my homepage? #41 (comment) - never seems to cache from there-on-in 😞

@lauragift21
Copy link
Collaborator

Closing this issue because the initial question was addressed. Also the templates have moved over to the worker-sdk monorepo: https://github.com/cloudflare/workers-sdk/tree/main/templates.

if you're still experiencing issues feel free to open an issue there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants