A single sitemap for a large catalog no longer fit within the allowed size, and after splitting it, some products disappeared from the XML. Splitting the file alone does not solve the problem: you need to preserve the full set of required URLs and be able to check which part contains each product.
Below is a custom educational example for Next.js 15 with the App Router. Published products have a numeric internal ID and a public slug. We distribute URLs across stable ID ranges. For a different identifier format, you can store the assigned group separately; do not convert a UUID into a number arbitrarily.
When to split a sitemap
A sitemap has limits on the number of URLs and the uncompressed file size: up to 50 000 URLs and up to 50 MB. If either limit is exceeded, the file should be split. A large catalog may hit the size limit first, especially when it includes additional data and language variants. Google's sitemap guidelines.
You do not have to wait until you reach the limit. It can be convenient to maintain several clearly defined parts by content type or stable product groups. However, dozens of empty files do not add useful URLs. First count the published pages you plan to include and measure the actual XML.
Define inclusion rules. For example, the educational sitemap includes published product pages with a canonical URL on the production domain. Drafts, private sections, temporary filters, and “product not found” responses are excluded. An out-of-stock product is not necessarily removed: that depends on whether its page remains useful and accessible.
Choose a stable way to distribute products
Simple numbering such as “the first 10 000 rows, then the next 10 000” depends on the sort order and list contents. If an earlier product is removed, the boundary shifts. This does not necessarily break the sitemap, but it makes it harder to find omissions, reconcile parts, and compare results reproducibly.
In our example, the group is calculated as the integer part of ID / 10 000. Group 0 contains IDs from 0 inclusive to 10 000 exclusive; group 1 contains IDs from 10 000 to 20 000. This rule keeps a product in the same place when neighboring product pages are published. The upper boundary must not be included in both parts.
Do not calculate the number of groups based only on the number of published products. If there are gaps in the IDs, a product with ID 95 000 will be skipped if you declare only the first group based on a short list. Build the list of existing groups from the actual published IDs. Empty groups do not need to be declared.
Use generateSitemaps for version 15
In Next.js 15 generateSitemaps declares the part identifiers, and the sitemap function receives id: number. Part URLs have the form /catalog/sitemap/0.xml. This differs from examples for other major versions; check the documentation for the installed package. generateSitemaps documentation for version 15.
The educational file app/catalog/sitemap.ts below uses two source adapters. You need to implement them in your project. The first returns the existing groups of published products; the second returns the published rows for the specified half-open range. Both must use the same publication rules.
import type { MetadataRoute } from 'next'
import {
listPublishedSitemapGroups,
publishedProductsInRange,
} from '@/lib/catalog-sitemap-source'
const GROUP_SIZE = 10_000
const PUBLIC_ORIGIN = 'https://shop.example.ru'
export async function generateSitemaps() {
const groups: number[] = await listPublishedSitemapGroups(GROUP_SIZE)
return groups.map((id) => ({ id }))
}
export default async function sitemap({ id }: {
id: number
}): Promise<MetadataRoute.Sitemap> {
const rows = await publishedProductsInRange({
fromInclusive: id * GROUP_SIZE,
toExclusive: (id + 1) * GROUP_SIZE,
})
return rows.map((product) => ({
url: new URL(`/catalog/${encodeURIComponent(product.slug)}`, PUBLIC_ORIGIN).href,
lastModified: product.publicContentUpdatedAt,
}))
}The domain in the code is illustrative: replace it with the agreed canonical domain. publicContentUpdatedAt means the date the public product page was substantially updated, not the date the sitemap file was retrieved. A change to a warehouse record that does not affect the page does not have to change this date. Validate the fields in the adapter before generating the XML.
Make the parts discoverable
Creating routes for the parts does not mean search crawlers already know their URLs. Prepare a sitemap index linking to the existing parts, or submit the required sitemaps through search engine tools. Check how the sitemap is declared in your project's robots.txt.
generateSitemaps should not be treated as a promise of a ready-made index containing all your other sitemaps. Open the actual index URL and compare its links with the declared groups. If separate blog or service sections have their own sitemaps, they also need a consistent discovery method.
Check the protocol and domain of every URL. A production sitemap must not contain preview URLs just because the build received an environment variable from a staging environment. Start with a few product pages from different parts, then run a full machine comparison. It is better to catch an incorrect domain in thousands of entries before submitting the file to a crawler.
Compare the URL sets, not just the counts
For verification, save a reference list of published product pages from the source at a specific point in time. Retrieve all sitemap parts and combine their URLs. Then compare the sets: what is missing, what is extra, and what appears more than once. The same number of entries does not prove that the lists are identical.
Be sure to include products at the range boundaries: IDs 9 999, 10 000, and 10 001. Add a product with a high ID after a long gap and check whether the required group appears. Check unpublishing: the page should disappear from the declared set without removing the other products in its group.
If the catalog changes while you are fetching all the parts, the comparison may cover different states. Pin the export version or run the check when the dataset is stable. Do not call a discrepancy a proven splitting error until you have ruled out concurrent data changes.
Separately check the status and content type of each file, XML validity, uncompressed size, and the URL limit. Do not mistake an HTML error template named sitemap.xml for a sitemap. Also choose real product pages from each part and open them: valid XML can still list the wrong pages.
How to maintain the sitemap after fixing it
In the developer task, document the group size, inclusion conditions, how the group list is obtained, and the criteria for changing lastModified. These rules must be shared by the index and the individual parts. Otherwise, an update to the source may add a new part while the index continues to list the old set.
After publishing, retrieve the sitemap directly and run a technical page check for the test URLs. A page audit does not replace a full comparison of thousands of sitemap URLs. Checking the list is a separate step, and its results should be attached to the task.
A sitemap supplements the catalog's own links. If product pages are accessible only through XML, review rendering products and links on a server-rendered page. The main application mechanisms are covered in the Next.js 15 guide.
After the change, monitor sitemap processing in the webmaster tools. Submitting a sitemap helps report URLs, but does not guarantee their indexing. The verifiable outcome of this work is a complete, valid, accessible set of required URLs with a clear update process.