Cache everything with WordPress


#1

Currently the “cache everything” option, which massively speeds up any website, does not work with WordPress because logged-in users will see non-logged-in cached content.

The only solution for this is to get a Business plan for $200 per month per site and use cookie exclusions.

Is there any chance this feature could be moved to the Pro or Free plan? It would improve millions of websites speed and change WordPress use forever!


Cloudflare works on both main and sub domain
#2

you might want to use page rules for specific static url asset uris matches to use ‘cache everything’ instead :slight_smile:


#3

You can follow the @eva2000 eva2000 advice which will work for sure or lookup the settings.

WP Admin sets “private”, “no-store”, “no-cache”, or “max-age=0” headers by default.
CF’s Cache Everything respects these headers and will not cache WP Admin part unless you set:

  • to cache it on origin
  • EDGE Cache TTL in page rules

Edge cache TTL will bypass every cache header and rewrite it to public with max-age set from the setting.

At the moment, four different ways are coming to my mind. You can:

  1. Follow @eva2000 advice to cache specific things
  2. Set appropriate cache headers on origin and just select Cache Everything without touching Edge cache TTL
  3. Set Browser cache level in CF’s Caching tab and just select Cache Everything without touching Edge cache TTL. If your origin TTL is shorter, it will increase it to the selected one. If origin is longer, it will use origin’s, and it will not rewrite private/no-store to public. (You can actually set Browser Cache TTL in the page rules also.)
  4. Create another page rule ordered above (important!), set the page rule for WP Admin (eg. www.domain.tld/wp-admin/*), select Bypass in the Cache Level setting.

Keep in mind that some features can be changed later on.

Always test during, and after deployment. :sunglasses:

I really like Cache Everything. It’s really powerful and should be used with care, or you will leak private data. :blush: :grinning:


#4

We agree with @Rubious. Please offer the Cache Everything with WordPress Page Rule feature to Pro plan users (as a minimum).


#5

I think there’s some misunderstanding here. The problem I highlighted is not that the WP admin is cached (it’s not), it’s that if you have any dynamic content for logged-in people (e.g. A My Account area) then those people will still see the cached, non-logged in pages.

The only way I can see to resolve this is a $200/ month business plan which is asking a lot really.


#6

6 posts were split to a new topic: Do I need to temporarily disable Cloudflare?


#12

Can a mod please split this topic? @twillis16 has totally gone off topic


#13

done. Thanks for the heads up


#14

Sorry for misunderstanding.

To skip paying an expensive plan just for cookie bypass option, you will need to set nocache/private/expire headers for this pages on your origin. The situation is really the same as WP-Admin - the only difference is that you will need to do it manually, while for WP-Admin it’s by default. So list from above applies, especially 4. if you have spare rules available.

I don’t know your architecture configuration - proxies, loadbalancers, etc, but lets assume it’s simple config.
You can set it on a server level - nginx conf or apache vhost / htaccess.
Or built it within the theme or plugin. Function for this is nocache_headers() or you can apply a hook for more granular control over the headers.

In case you are using caching plugins, such as w3tc or super cache, you will need to tell them not to cache these pages (within own settings or code blocks), as they will overwrite the headers and cache the output anyway.

Business plan offers a railgun, which you can use for dynamic content when your visitors are logged in. :slight_smile:


#15

Hi,

Using Cache Everything page rule with WordPress on Free or PRO plan is not so easy.

I have implemented Cache Everything rule on my blog and I know that what’s all problem I having to face. I think, without switching to Business plan, these problem are not going to be resolved.

#####Since HTML document change according to the WordPress logged in or non-logged in WordPress user and it get cached also.
In logged in case, and suppose the header response is HIT (To reproduce: visit any own page while logged in and see what happens).

  • Near WordPress Native Comment box, it will say Logged in as admin? Well we can leave comment without entering name, email and website. But, this is not suitable for a visitor.

  • Similary, there are few plugin or script (For ex: Google Analytics) which we never want to trigger while we are logged in the browser. But with Cache Everything it can either miss or hit based on first user visit.

Anyway, It would be truly helpful for us, If Cloudflare offer bypassing cache based on cookies for the PRO plan also. Many many thanks in advance to Cloudflare team.


#16

Update: I got a solution for this, avoid using Edge Cache at page rule. So CF will not ignore cache-control policy such as must-revalidate, no-cache, private.


#17

@GulshanKumar do you mean you’ve found a solution for caching everything? Can you explain further please?


#18

Would be awesome if someone from the Cloudflare team can answer our question about offering Cache Everything with Wordpress Page Rule to Pro Plan users.


#19

Does your solution provide the same results as the “Bypass Cache on Cookie” wordpress setting noted in the link below?

Speed Up WordPress and Improve Performance


#20

@Aviator how it can provide a solution like that :slight_smile:
@Rubious At some extent, you can achieve similar experience if you avoid using Edge Cache rule at Page rule and, use only Cache Level with Everything rule. That’s it.


#21

We are always considering which features can be made available at different plan levels, but I don’t have any other details on that right now. I’ll be sure to pass along the feedback to the team.


#22

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.


#23

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


#24

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.


#25

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