How to exclude XML and XSL files from caching plugins

XML sitemaps should never be cached so that Google and other search engines can read their content correctly.

The stylesheet associated in XSL format (equivalent to CSS but for XML), should not be cached either.

Most of the caching plugins automatically exclude these URLs from caching but it’s not always the case.

WP-Rocket

They does the job for you! Nothing to exclude.

We are fully compatible with their Preloading sitemap feature:

WP Rocket Sitemap Preloading for SEOPress
WP Rocket Sitemap Preloading for SEOPress

W3 Total Cache

Add these rules to Performance > Page cache:

Never cache the following pages:

[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml
W3 Total Cache - Exclude Sitemaps from caching
W3 Total Cache – Exclude Sitemaps from caching

Save settings and clear your cache.

Autoptimize

Nothing to exclude. Works out of the box.

WP-Optimize

Nothing to exclude. Works out of the box.

Hummingbird

Add these rules to Hummingbird > Caching page > Exclusions section:

[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml
Hummingbird - Exclude Sitemaps From Caching
Hummingbird – Exclude Sitemaps From Caching

Save settings and clear your cache.

WP Super Cache

Add these rules to Settings, WP Super Cache, Advanced:

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

Save strings and clear the cache.

WP Super Cache - Exclude sitemaps from caching
WP Super Cache – Exclude sitemaps from caching

Last modified: July 3, 2020