Guides
Sitemap Chunking
 Last updated  by 
Harlan Wilton
 in feat: automatic chunking for multi-sitemaps (experimental) (#451). Introduction
When dealing with large datasets, sitemap sources can be chunked into multiple files to:
- Stay within search engine limits (50MB file size, 50,000 URLs)
- Improve generation performance
- Better manage memory usage
Simple Configuration
Enable chunking on any named sitemap with sources:
nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      posts: {
        sources: ['/api/posts'],
        chunks: true, // Uses default size of 1000
      }
    }
  }
})
This generates:
/sitemap_index.xml    # Master index
/posts-0.xml          # First chunk (1-1000)
/posts-1.xml          # Second chunk (1001-2000)
...
Chunk Size Options
Configure chunk sizes using different approaches:
nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    // Global default
    defaultSitemapsChunkSize: 5000,
    
    sitemaps: {
      // Using boolean (applies default)
      posts: {
        sources: ['/api/posts'],
        chunks: true,
      },
      
      // Using number as size
      products: {
        sources: ['/api/products'],
        chunks: 10000,
      },
      
      // Using explicit chunkSize (highest priority)
      articles: {
        sources: ['/api/articles'],
        chunks: true,
        chunkSize: 2000,
      }
    }
  }
})
Practical Examples
E-commerce Site
nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    defaultSitemapsChunkSize: 10000,
    sitemaps: {
      products: {
        sources: ['/api/products/all'],
        chunks: 2000,
      },
      categories: {
        sources: ['/api/categories'],
        chunks: true, // Uses default 10k
      }
    }
  }
})
Large Content Site
nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      'blog-posts': {
        sources: ['/api/blog/posts'],
        chunks: 5000,
      },
      authors: {
        sources: ['/api/authors'],
        chunks: false, // Explicitly disable
      }
    }
  }
})
Source Implementation
Basic endpoint for sitemap sources:
server/api/products/all.ts
export default defineEventHandler(async () => {
  const products = await db.products.findAll({
    select: ['id', 'slug', 'updatedAt']
  })
  
  return products.map(product => ({
    loc: `/products/${product.slug}`,
    lastmod: product.updatedAt
  }))
})
For large datasets, use caching and streaming:
server/api/products/all.ts
export default defineCachedEventHandler(async () => {
  const products = []
  const cursor = db.products.cursor({
    select: ['slug', 'updatedAt']
  })
  
  for await (const product of cursor) {
    products.push({
      loc: `/products/${product.slug}`,
      lastmod: product.updatedAt
    })
  }
  
  return products
}, {
  maxAge: 60 * 60, // 1 hour cache
  name: 'sitemap-products'
})
Debugging
Check chunk configuration and performance:
nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    debug: true,
    sitemaps: {
      products: {
        sources: ['/api/products'],
        chunks: 5000
      }
    }
  }
})
Visit /__sitemap__/debug.json to see chunk details and generation metrics.
 Did this page help you?