Cache everything with WordPress


#28

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


#29

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.


#30

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!


#31

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.


#32

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


split this topic #33

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


#34

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


#35

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.


#36

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.


#37

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


#38

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!


#39

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.


#40

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


#41

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.


#42

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

why this doesn;t work not a woocommerce


#43

because of multiple dynamic pages and things on homepage like add to cart, login, but coupon and other different types of dynamic areas


#44

Is this possible with cloudflare workers?
Caching every request except for logged user.


#45

That sounds like Bypass Cache on Cookies, which is an Enterprise feature. If someone could rig it up through Workers, that’d be super!


#46

Hello guys,

I have tried to tackle this problem by appending query string to every link when admin is logged in, by doing this in funcions.php

function add_admin_qs($url){
if ( is_user_logged_in() ) {
return add_query_arg(‘nocfcache’, ‘true’, $url);
}
}

if ( is_user_logged_in() ) {
add_filter( ‘home_url’, ‘add_admin_qs’, 11, 1);
add_filter( ‘post_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘page_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘post_type_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘category_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘tag_link’, ‘add_admin_qs’, 10, 1);
add_filter( ‘author_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘day_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘month_link’, ‘add_admin_qs’, 11, 1);
add_filter( ‘year_link’, ‘add_admin_qs’, 11, 1);
}

This code will append query string yoursite/yourpost?nocfcache=true, then you create page rule,
bypass cache 1st: arg *yoursite.com/nocfcache=true

Now when you login to your panel every link page/post will have that query string appended which will tell cloudflare to bypass those URLs and will not cache your admin data, you can create then these 3 rules:

  1. Bypass *yoursite/nocfcache=true
  2. Bypass yoursite/wp-admin
  3. Cache everything yoursite/

Edit: add wildcards before and after nocfcache=true, the cloudflare forum editor is stripping them for some reason.

Install Sunny plugin to purge on post/page publish.

This method should work with woocommerce and dynamic logged in users as it will bypass cache for those users, but needs more testing.

I created it for my static websites and news portals, can anyone help me find flaws within this method as it is in beta for me?

Thanks


#47

Whilst yes that probably does work, it’s problematic to add a query string next to every URL. If a user shares the page, they will probably share the query string as well which will mean you’ll get lots of visitors to the non-cached page, not great for the server.