Excluding the XML Sitemap from caching

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.  This is because you don’t want search engines getting old cached information, you want them to ALWAYS get the current sitemap for your site.

Here we cover how to exclude your XML Sitemap from caching in the most popular caching plugins.

LiteSpeed Cache

To exclude the XML Sitemap from caching in LiteSpeed Cache, go to LiteSpeed Cache > Cache > Excludes and enter the following in the Do Not Cache URIs field:

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl

WP Fastest Cache 

To exclude the XML Sitemap from caching in WP Fastest Cache, go to WP Fastest Cache > Exclude and click on the Add New Rule button next to Exclude Pages.  In the dropdown, select Contains, and in the field, type sitemap and click Save.

WP Rocket

To exclude the XML Sitemap from caching in WP Rocket, go to Settings > WP Rocket > Advanced Rules > Never Cache URL(s) and enter the following:

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl

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:

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

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” and enter the following:

sitemap(_index)?\.xml(\.gz)?
[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.

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.