---
title: "Sitemap Chunking"
description: "Split large sitemap sources into multiple files for performance and search engine limits."
canonical_url: "https://nuxtseo.com/docs/sitemap/advanced/chunking-sources"
last_updated: "2026-05-25T04:24:18.208Z"
---

## 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:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      posts: {
        sources: ['/api/posts'],
        chunks: true, // Uses default size of 1000
      }
    }
  }
})
```

This generates:

```text
/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:

```ts [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,
      }
    }
  }
})
```

## Skipping the index source fetch (`chunkCount`)

By default the sitemap index calls your source to count URLs, so it knows how many `<sitemap>` entries to emit. At very large scale this cold-start fetch is the bottleneck. If you already know the number of chunks, declare it upfront and the index will skip the fetch entirely:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  sitemap: {
    sitemaps: {
      posts: {
        sources: ['/api/posts'],
        chunks: 5000,
        chunkCount: 100, // 100 chunk entries, no source fetch in the index
      },
    },
  },
})
```

Per-chunk renders still fetch on demand and slice. If your data set grows past the declared count, tail entries are unreachable; if it shrinks, trailing chunks render empty. Update the value when your data set changes (or remove it to fall back to fetching).

## Practical Examples

### E-commerce Site

```ts [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

```ts [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:

```ts [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:

```ts [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:

```ts [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.
