This article provides a simple trick to reduce the load on the server when generating a sitemap. We do this by disabling all widget-related code if the current request targets the sitemap or its stylesheet. The trick is compatible with many existing plugins.
The article describes a way to use custom XML stylesheets for sitemaps generated by Yoast SEO plugin. Custom stylesheets can be good if you want to get rid of spammy links back to Yoast website in every generated sitemap file.