• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Startup Hero

The Official Blog Of Name Hero

Learn To Fly Above The Competition Get Started
  • HomeWelcome
  • CoursesVideo Training Center
  • About UsWhat is StartupHero?
  • BlogGet the latest
  • Start HereStartup 101
  • SpeakingPodcast & Media
  • ResourcesTools to help You
    • Reselling WordPress Hosting
    • Resell Hero
    • How To Start A Blog
  • NameHeroCloud Web Hosting

How To Exclude Parts Of A Page From Caching In WordPress

By Bhagwad Park on March 9, 2022 0

How To Exclude Parts Of A Page From Caching In WordPress

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 the inventory stock for a product. 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!

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

Connect With Us!

Superhero Resources

Fix Common Issues

  • How To Setup Free And Automatic SSL Certificates
  • How To Setup Cloudflare With Railgun
  • How To Fix Memory Exhausted Errors In WordPress
  • How To Edit PHP Version/Upload Limit/Add Extensions
  • How To Move/Migrate Your Business To Name Hero

Free Guides

  • How To Setup NameHero Hosting
  • How To Create A Web Hosting Business With WordPress
  • How To Start A WordPress Blog
  • How To Migrate WordPress To A VPS
  • How To Speed Test And Optimize Your WordPress Website
  • Magento 2.X Installation Guide
  • How To Clean Up A WordPress Hack

Training

Recent Posts

  • The Best WordPress Plugin To Combat Plagiarism
  • Is It Time to Bring Back Blog Comments?
  • Two Filters That No Longer Work In Gutenberg (And Workarounds)
  • Migrating To The New Cloudflare Managed Rules Interface
  • How To Sort Posts By The “Last Modified” Date
  • How To Make WordPress Send E-mail From Another Address
Subscribe in a reader
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • VPS Hosting
  • Twitter
  • Facebook
  • LinkedIn
  • YouTube
  • FTC Disclosure
  • Earnings Disclosure
  • Privacy Policy

Copyright © 2023 · Smart Passive Income Pro on Genesis Framework · WordPress · Log in