Sitemap
Guides

Sitemap.xml Best Practices

The best practices for generating a sitemap.xml file.

Performance

When dealing with many URLs that are being generated from an external API, the best option is use the sitemaps option to create Named Sitemap Chunks.

Each sitemap should contain its own sources, this allows other sitemaps to be generated without waiting for this request.

export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      posts: {
        sources: [
          'https://api.something.com/urls'
        ]
      },
    },
  },
})

If you need to split this up further, you should consider chunking by the type and some pagination format. For example, you can paginate by when posts were created.

export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      posts2020: {
        sources: [
          'https://api.something.com/urls?filter[yearCreated]=2020'
        ]
      },
      posts2021: {
        sources: [
          'https://api.something.com/urls?filter[yearCreated]=2021'
        ]
      },
    },
  },
})

Additionally, you may want to consider the following experimental options that may help with performance:

  • experimentalCompression - Gzip's and streams the sitemap
  • experimentalWarmUp - Creates the sitemaps when Nitro starts

Set appropriate lastmod

The lastmod field is used to indicate when a page was last updated. This is used by search engines to determine how often to crawl your site.

This should not change based on code changes, only for updating the content.

For example, if you have a blog post, the lastmod should be updated when the content of the blog post changes.

It's recommended not to use autoLastmod: true as this will use the last time the page was built, which does not always reflect content updates.

Learn more https://developers.google.com/search/blog/2023/06/sitemaps-lastmod-ping

You probably don't need changefreq or priority

These two fields are not used by search engines, and are only used by crawlers to determine how often to crawl your site.

If you're trying to get your site crawled more often, you should use the lastmod field instead.

Learn more https://developers.google.com/search/blog/2023/06/sitemaps-lastmod-ping