Last updated on

When implementing a Page Fragment Caching Exception, you are telling W3 Total Cache to bypass cache for a particular section of content. A great use case for this is dynamic content that you wish to update real time, separate of the page caching itself. The following article will walk you through the process.

Speed Up Your WordPress Website.

A Difference of Just 100ms in Page Load Speeds Can Cause a Visitor to Prefer Your Competitor’s Website.

  • Select your fragment caching method in Performance → General Settings
  • Enable “late initialization” on the Page Cache settings page
  • Add define(‘W3TC_DYNAMIC_SECURITY’, ‘mycode’); to your wp-config.php file

And finally, use this format to implement the caching exception in your template for the dynamic content:


Implementing a Page Fragment Caching Exception for Comments in Twenty Twenty

The following example demonstrates how to configure an exception group for blog post comments using the default WordPress theme, Twenty Twenty and W3 Total Cache.

Resources:

  • Twenty Twenty theme
  • Twenty Twenty child theme

Install both themes in your WordPress installation and activate the Twenty Twenty child theme.

Copy the comments.php file from the Twenty Twenty theme over to the child theme root directory.

Install and activate W3 Total Cache and set your Pro license.

Navigate to Performance > General Settings and enable Page Cache.  If you do not have memory based caching available on your server (Redis or Memcached) the select Disk: Basic for the Page Cache Method.

Access your Page Cache settings by navigating to Performance > Page Cache in your WordPress dashboard and enable Late initialization under the Advanced section.

Add the code define(‘W3TC_DYNAMIC_SECURITY’, ‘comments’); to the wp-config. php file associated with your website just before the line /* That’s all, stop editing! Happy publishing. */

Open comments.php located in your child theme directory using your preferred text editor.

Locate the wp_list_comments function and wrap it in your <!– mfunc comments–> opening and closing tags.  Your code should look like this:

 

W3 Total Cache

You haven't seen fast until you've tried PRO

   Full Site CDN + Additional Caching Options
   Advanced Caching Statistics, Purge Logs and More

Everything you need to scale your WordPress Website and improve your PageSpeed.

2 thoughts on “How to Implement Page Fragment Caching Exception in W3 Total Cache

  1. abitofmind says:

    Your code should look like this: CODE

    And then the article ends seemingly apruptly

    How does this continue?
    – Save the functions.php.
    – Then X
    – Then done

    Then your website will behave like this:
    – Short roundup of how Fragment Caching works
    – And/or a good article how WordPress works in that regard.

    The article in its current form feels very incomplete. As if the editor saved it as a draft halfway and it then it got published that way. The essence is missing.

Leave a Reply

Your email address will not be published. Required fields are marked *