Excluding the XML Sitemap from caching

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

Many people utilize caching of some type to speed up their website.  Caching can be done at the server level by your hosting provider or at the WordPress level using a caching or performance plugin.  However, some files should never be cached such as the XML Sitemap files.  This is because you don’t want search engines getting old cached information, you want them to ALWAYS get the current copy of these files.

Here we will cover how to exclude the XML Sitemap from caching by the top 3 most popular WordPress caching plugins – WP Super Cache, W3 Total Cache and WP Rocket.

 

WP Super Cache – https://wordpress.org/plugins/wp-super-cache/

To exclude the XML Sitemap from caching in WP Super Cache go to Settings  > WP Super Cache and click on the Advanced tab.  Scroll down to the section where it says “Add here strings (not a filename) that forces a page not to be cached” and enter the following string in the box:

[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml

 

W3 Total Cache – https://wordpress.org/plugins/w3-total-cache/

To exclude the XML Sitemap from caching inW3 Total Cache go to Performance > Page Cache and scroll down to the section where it says “Never cache the following pages”.  Enter the following strings in the box:

[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml

If you are using Database Caching then add the same strings to the “Never cache the following pages” under Performance ? Database Cache.

If you are using Minification then go to Performance > Minify and enter the same strings in the field under “Never minify the following pages”.

Finally, go to Performance > Browser Cache and make sure the same strings are in the “404 error exception list” field.

 

WP Rocket – https://wp-rocket.me/

To exclude the XML Sitemap from caching in WP Rocket go to WP Rocket > Advanced Options and scroll down to the section where it says “Never cache the following pages”.  Enter the following strings in the box:

[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml

Always remember to clear all caches after making these changes in either of the three plugins.

If you are using a different plugin or caching is done at the server level then contact the plugin developer or your hosting company for support.

[i]
[i]
Skip to toolbar