PLEASE HELP with Page Rules and 'dynamic content'

Hey guys

New to Cloudflare. Just some quick info- I am hosted on Kinsta. Please also note I am not that technical :slight_smile:

So after reading a host of articles, I’ve started playing around with the Page Rules within CloudFlare, and also have the Wordpress Plugin to enabled automatic cache management.

1 website URL/preview=
Cache Level: Bypass On

2 website URL/?s=*.
Cache Level: Bypass On

3 website URL/wp-admin*
Browser Integrity Check: On, Security Level: High, Cache Level: Bypass, Disable Apps, Disable > Performance On

4 website URL/

Cache Level: Cache Everything

So I have the above rules enabled right now, and all seems fine (unless someone tells me otherwise) apart from… the Full Page Cache rule!

The vast majority of the site is static, however there are a few areas which I guess can be classed as ‘dynamic’ and I can’t work out why I am not being served the latest versions of some things. Let me bring it to life

If I take my posts (single posts) for example, there are calls to various PHP files which will load content. One such example is within here:

Below the tags there is some Google Matched Content. This code is generated from: (Will refer to as Outbrain.php from now on due to link restriction limit)

Now that file will maybe be updated once or twice a year. I’ll maybe change Google Matched Ads to Taboola code or something for example.

Here are the steps I undertook to test this:

  1. Add a rule to ‘bypass cache’ for outbrain.php and put at Number 1 in the list.

  2. Updated said file with some generic text.

  3. Customed purged URL: outbrain.php

Following this, I tested some single post links and they were still showing the old version!

The only way to resolve this for me was to turn off the Cache Everything site-wide rule, purge specific post URLs or purge everything.

I think I am probably getting confused with best practice steps I need to take for scenarios like this so would appreciate some guidance for this specific scenario on what would be right steps/changes to make in future. There are other scenarios I have like this on the site with items in the sidebar for example too which reference specific PHP files.

Thank you so much

Can you provide examples of URLs which are static and of which are not?

If their URLs are not fundamentally different you wont be able to cache everything.

The other approach would be that you still cache everything but force a cache purge whenever you do make a change. Of course that will only work if you do not have any user logins.

Sorry when I say static, I may have the terminology wrong.

This is a static page but the ‘Latest News’ sidebar on the right is a widget displaying all single posts from all categories. Is this page therefore dynamic? Is an example of a single post. Again, Latest News in the sidebar is performing the same function and needs to show up to date posts. As I said in the original post too, single posts call on some PHP files to display ads etc but these are very rarely changed.

Does that make sense? In terms of your other point, I have enabled automatic cache in the Cloudflare plugin on Wordpress so it should do a purge automatically but I think it only applies to post updates or switching themes.

That is still part of that page, hence the page itself cannot be cached.

From what I can tell you should probably only use Cloudflare’s default caching policies.

Ah! Ok that’s annoying

What if I cached just index.php?

If that is all you want to cache and there are no dynamic elements, you can certainly go for it.

Essentially, you should only cache URLs which do not necessarily need to reach your server.

That seemed to work fine I think. As Automatic Cache is enabled for Post additions/edits, it means that the the homepage is updating as those elements or contained within that page. I made an edit to a header title in the sidebar, and while that did not updated instantly, it did when I modified or added a post.

One other thing I was wondering around was advertisements. My theme uses ‘Ad Inserter Pro’ which is injected into the theme, and are obviously called on the Homepage. These will essentially be cached if I do the index.php thing but wondering if that is ok given this is essentially external code? I am thinking technically it is only caching the actual ‘code’ which for example is the below, so it shouldn’t affect revenue or anything?

<!-- GPT AdSlot 1 for Ad unit 'we_multisize_top' ### Size: [[970,250],[970,90],[728,90],[320,50],[300,100]] -->
<div id='div-gpt-ad-5252391-1'>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-5252391-1'); });
<!-- End AdSlot 1 -->

If that is always the same code it wont matter. If it is not, you will still run into caching issues.

Yep that code is always the same.

I added index.php but seems to make no difference on TTFB on Pingdom. Only when I enable caching site-wide does the performance noticeably improve. Will have to just live without it I guess.