• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Exclude Parts Of A Page From Caching In WordPress

Bhagwad Park

Published on: March 9, 2022

Categories: WordPress 0

Caching is the secret sauce that can transform a slow page into one that loads blazing fast. There are many layers of caching – you can cache on the origin server, a POP endpoint, and even the browser. Using these techniques, you can obtain cache hit ratios of over 90% on networks like Cloudflare. However, these techniques are only effective for mostly static sites. As soon as there’s a dynamic component, you have to be very careful about what you cache. However, there are ways to work around this. And today, I came across a great WordPress plugin that makes it easy to exclude certain parts of a page from caching.

Caching Dynamic Pages is a Challenge

Let’s say your page shows the latest stock price. Or even the time or date. Perhaps you have a PHP snippet that calculates inventory or a plugin that synchronizes inventory between your online and physical store. None of these pieces of information can be cached. They must always be up-to-date – sometimes on a second-to-second basis. It’s a real shame because most of the time, you don’t want the entire page to be generated from scratch. It’s just a few elements that need to be dynamic while the rest of the page layout and text remain the same.

Fragment Caching Doesn’t Help

Plugins like W3 Total Cache have something known as “Fragment Caching”, where you can exclude certain items from the server cache. But if you use a system like Cloudflare to cache the page, fragment caching won’t help you, because Cloudflare stores the result of the server in its “Full HTML caching” functionality.

Using the Content No Cache Plugin

Recently, I came across this WordPress plugin that lets you create dynamic content that’s never cached – not even by Cloudflare when in full caching mode. It’s called Content No Cache. You can download and install it from the WordPress plugin repository.

After installation, you navigate to the “Content No Cache” section on the WordPress admin dashboard and create your dynamic content like this:

Creating the Dynamic Content to Exclude from Caching
Creating the Dynamic Content to Exclude from Caching

Now, of course, you could write a PHP snippet for this and insert it as a shortcode so that it computes automatically every time the page is loaded. Once you save this, you can use the provided shortcode to insert the dynamic content into a regular post/page. Like so:

Insert the Dynamic Shortcode into the Page
Insert the Dynamic Shortcode into the Page

And when the page renders, this is what you see:

Dynamic Content Excluded
Dynamic Content Excluded

This Even Works with Cloudflare’s “Cache Everything”

The best part about this method is that it even bypasses Cloudflare’s “Cache Everything”, which saves the HTML returned from the server. It works because the dynamic content is rendered in real-time via JavaScript instead of plain HTML. So this technique works perfectly with Cloudflare. Here’s a screenshot of the Cloudflare header status showing a “HIT” while displaying dynamic content:

Cloudflare Registers the Page as a "HIT"
Cloudflare Registers the Page as a “HIT”

For me, this is the killer feature.

Full Site Caching is Now Accessible Even for Dynamic Pages

Full site caching is the magic sauce that can make even slow web pages load instantly. Using QUIC.cloud, NameHero users can reduce their TTFB times by as much as 500%! But it’s not particularly useful if your site depends on dynamic elements. Using the Content No Cache plugin, you can now extend full site caching even for moderately dynamic sites as long as you’re able to set it up properly with PHP in the backend to get the values in real-time.

This solution beats fragment caching as implemented on server caching plugins like W3 Total Cache. So go out there and use it!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Why I Don’t Use Jetpack Backup

I don't use Jetpack Backup, because of pricing issues, and the fact that I worry it won't be able to save me from a severely hacked site.

How To Scale Your High Traffic WordPress Site

Check out our article demonstrating our deep knowledge of scalable WordPress hosting, including WordPress bottlenecks and optimal equipment.

Problems With Fully Managed WordPress Hosting

While fully managed WordPress hosting plans promise speed and security, here's a list of problems that you will encounter.

Speed up your site: solving the WordPress slowdown

Don't let a slow WordPress site affect your conversion rates! Explore our comprehensive guide to optimize loading speeds and offer a superior user experience. %

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA