Cache everything with WordPress

Thanks, @ryan. Based on good program management practices, when do you think Cloudflare will make a decision? FYI, our company always logs requests and returns an answer (usually positive) by the assigned due date. Cheers.

I came across an interesting post which suggested using a combination of 3 Page Rules (available in the Free Plan) with a WordPress plugin ( Called Sunny, for automatically doing individual file purge request via Cloudflare API when content is updated)

The post is - https://collinmbarrett.com/wordpress-Cloudflare-dynamic-caching/

The plugin they suggested is - https://wordpress.org/plugins/sunny/

This does look like it’s viable because Cloudflare API has very high rate limit (1200 request per 5 minutes period ) and should work for dynamic sites as well. Haven’t tried this yet though

Thanks for sharing, however I don’t think this does what we want - it would still show logged-in users with the logged-out cache so it’s not suitable for sites with memberships.

1 Like

Apologies, I missed that in the above discussion. Yes, that is indeed an issue for logged-in users.

I had a question is the membership area limited to a specific folder of your site (like mydomain.tld/members-area/* )

If that is the case, then instead of the “mydomain.tld/?p=” page rule suggested in the tutorial ( That is not needed because the Page Preview URL structure is different - Refer to https://wordpress.stackexchange.com/questions/218588/post-preview-mechanism-architecture) you can make use of that rule to make the membership area uncacheable

No, for example every page would say “welcome Shaun” and there would be changes throughout the whole site.

What we’d need is a way to detect who is logged in and not serve any cache to them. This currently requires a Business plan which is $200 per month :persevere:

1 Like

Then it is indeed a bit more difficult to implement.

One idea that I can think of, is to add a unique query string to the URL for logged in users (suppose like ?loggedin=true). You will need to implement some logic via JavaScript as well to check if a logged in user cookie is present, then they always open the URL with the ?loggedin=true query string appended (This is needed in case the logged in user by mistake opens the URL without the query string, I am assuming, there will be some unique cookie which set when a user logs in)

Then you can implement Page Rule for caching everything on the site other than when that unique query parameter is present in the URL ( The Page Rule for the unique query string parameter will look like - “mydomain.tld/*?*loggedin=true” , Refer to https://support.cloudflare.com/hc/en-us/articles/200172256 . We will be using this page Rule to replace the “mydomain.tld/?p=” one suggested in the tutorial)

So the 3 Page Rules would look something like

  1. mydomain.tld/wp-admin
    Cache Level - Bypass

  2. mydomain.tld/*?*loggedin=true
    Cache Level - Bypass

  3. mydomain.tld/*
    Cache Level - Cache Everything

Hi Prayag

Yes that would work, however it’s a really hacky way of doing it, and there are all sorts of reasons why this is a bad idea I’m afraid.

The best way would be if we could detect cookies in our Page Rules, but Cloudflare are keeping that behind a $200/month paywall.

Thanks

4 Likes

You may want to try caching at the server with a wordpress plugin. You’ll get nearly a 10x speed boost with Comet Cache - and it is public/admin aware.

What do you think would be some of the .httaccess rules that could be set? (possible code example) Using a domain mapping plugin, i find that i’m getting stuck in an infinite loop(the plugin does some iframing or javascript redirect thingy to set a cookie on the domain), so would like to check for if the user is logged in /or if a woocommerce cart cookie is set and then get Cloudflare not to attempt to cache or show a cached page.

Thanks!

Has there been any update on this?

Been driving me crazy my clients who are editing their websites aren’t technical enough to understand that they can’t view the website when they are logged in.

Please come up with some kind of solution via page rules or .htaccess some kind of turn on-off option in Cloudflare dashboard.

Great reading everyone’s thoughts. The only thing I have come up with that is somewhat viable which is similar the too sunny plugin is: Auto Hide Admin Bar.

Also, how hasn’t Cloudflare’s team come up with some solution for this there are threads going back 3 years.
Crazy

A post was split to a new topic: How to use argo

that’s what Cloudflare page rules are for = finer grain caching definitions

There is a solution that is directly through Cloudflare…but ya gotta pay for it. Cloudflare has to pay the billz somehow! But for many its a cost prohibitive solution at 200/mo.

Well duh. but if you already have a caching plugin onsite like say autoptimize or wp-rocket.

It will still end up caching the admin bar. regardless of what page rules you use.

If you have the and example of a work around please share.

Yeah not trying to pay 200 a month for my clients simple 5 page website.

1 Like

I agree they should have a lower priced tier for that… Would be awesome
if it was free, but they gotta keep the lights on somehow!

domain.tld/wp-* cachelevel bypass 1st
domain.tld/* cachelevel everything

by adding my 1st rule my Cloudflare request dropped 85% to 50% is there any logic.

Unfortunately that does not help if you have a site with users who log in (e.g. WooCommerce)

Yes it caches the admin bar, but it will show a different cache to a logged-in user than to a logged-out user, so it’s not the same issue we’re talking about here.