Next.js Sitemaps for Directories: What Google Reads
Google discards two of the fields Next.js hands you. The size limits, the lastmod rules and the path trap that breaks a split directory sitemap.
A directory with forty thousand category-and-city pages has exactly one file
deciding which of them Google hears about first, and on a Next.js site that
file is usually forty lines of TypeScript nobody has opened since launch. Four
rules govern whether it works: size, location, host, and the honesty of your
lastmod. Walk your own app/sitemap.ts against them and you will know in
about ten minutes whether the file is helping Googlebot or lying to it.
None of these rules are new. The sitemaps protocol page still carries a "last updated" stamp from November 2016, years before the App Router shipped, which is why the framework defaults sit slightly askew to it.
Two of the fields Next.js offers you are read by nobody
The MetadataRoute.Sitemap type invites you to set changeFrequency and
priority on every entry. Both landed in v13.4.14 according to the
file convention's version history,
and both appear in the framework's own example code.
Google's position on them is one sentence long, from the
build-and-submit page:
"Google ignores <priority> and <changefreq> values."
The protocol never promised much
either. It describes changefreq as "a hint and not a command" and says
outright that priority "is not likely to influence the position of your URLs in
a search engine's result pages," since it only ranks your own URLs against each
other.
So the fields are inherited furniture. The sitemap that serves this site still emits both on every single entry:
// app/sitemap.ts — read 13 September 2026
{
url: `${BASE_URL}/use-cases`,
lastModified: useCaseIndexLastMod,
changeFrequency: "monthly", // ignored by Google
priority: 0.9, // ignored by Google
}Nobody noticed. Nobody would. On a six-page marketing site leaving them in is harmless, and on a directory it is a tax you pay fifty thousand times without ever seeing the bill. Delete them and nothing breaks.
Past 50,000 URLs, one sitemap.ts is out of spec
Both limits come from the protocol and Google restates them verbatim: no more than 50,000 URLs and no more than 50 MB uncompressed per sitemap file. You may gzip the file for transfer; the ceiling is measured on the uncompressed size regardless.
For a directory the URL count binds first, and it is not close. Count the
characters in one of your own <url> blocks — a location plus a date is on the
order of 150 bytes with a typical directory slug, which puts fifty thousand of
them under 10 MB. You will hit the URL wall with most of the byte allowance
untouched. Keeping changefreq and priority adds roughly 60 more characters
per entry and still leaves you far below 50 MB, which is why those fields cost
you bytes rather than a breakage.
Next.js splits with
generateSitemaps:
// app/listings/sitemap.ts
export async function generateSitemaps() {
const { count } = await countPublishedListings()
return Array.from({ length: Math.ceil(count / 45_000) }, (_, id) => ({ id }))
}
export default async function sitemap(props: { id: Promise<string> }) {
const id = Number(await props.id) // v16: id resolves to a string
const rows = await getListingPage({ offset: id * 45_000, limit: 45_000 })
return rows.map((row) => ({
url: `${BASE_URL}/${row.slug}`,
lastModified: row.updated_at,
}))
}Two details in there are deliberate. The shard size is 45,000 rather than
50,000, because a directory that imports a CSV on Tuesday should not discover
on Wednesday that shard 3 overflowed. Sharding is also the point where the
build-time question shows up again — how many of those pages you prerender
versus render on demand is
a separate decision with its own failure modes.
And id is awaited: as of Next.js 16 it
arrives as a promise resolving to a string, which the framework's own older
example silently papered over with arithmetic coercion.
Splitting the sitemap does not give you a sitemap index
This is the part that catches people, because the two mechanisms look like they must be connected.
generateSitemaps publishes your shards at /listings/sitemap/0.xml,
/listings/sitemap/1.xml and so on. Nesting sitemap.ts inside route segments
publishes them at /products/sitemap.xml. Neither approach emits a
<sitemapindex> file that points at the set. Next.js documents both splitting
methods and never mentions producing one, because it doesn't.
Which leaves two honest options.
List every shard in robots.txt. The protocol allows it and Google is explicit
that "there's no limit to the number of sitemaps you can include in your
robots.txt file." In Next.js the sitemap key on the robots object already
accepts an array:
// app/robots.ts
export default function robots(): MetadataRoute.Robots {
return {
rules: [{ userAgent: "*", allow: "/", disallow: ["/api/", "/admin/"] }],
sitemap: [
`${BASE_URL}/sitemap.xml`,
`${BASE_URL}/listings/sitemap/0.xml`,
`${BASE_URL}/listings/sitemap/1.xml`,
],
}
}Or write the index yourself as a route handler. It costs about fifteen lines
and buys you something the robots.txt list cannot: a lastmod on each shard
entry. The protocol says that timestamp lets a crawler "retrieve only a subset
of the Sitemaps in the index," which on a directory where one city's listings
changed and eleven others didn't is the difference between a targeted refetch
and eleven wasted ones.
Yoast's own functional specification
describes an index at /sitemap_index.xml with a lastmod on every
sub-sitemap, regenerated as content is added or removed — no configuration,
no route handler. If nobody on your team is going to own this file, that is a
real argument for WordPress over a codebase, and it says nothing about which
one can build the better directory.
Where the file sits decides which URLs are allowed in it
Now the rule that costs directories the most, and the one almost no sitemap guide mentions.
A sitemap covers only the URLs beneath its own parent directory. From Google: "unless you submit your sitemap through Search Console, a sitemap affects only descendants of the parent directory." The protocol is blunter — URLs outside that prefix "are dropped from further consideration."
Put that next to what generateSitemaps does. A shard at
/listings/sitemap/0.xml has /listings/sitemap/ as its parent, so by the
protocol it speaks for /listings/sitemap/... and nothing else. Now look at
where programmatic directory pages actually live. In DirectoryLaunch the
local SEO slug pattern defaults to
{category}-in-{city}-{region}, which renders /hvac-services-in-roseville-ca
at the root. Every one of those URLs sits outside the shard's scope.
Two ways out, and they are not equivalent:
- Submit each shard in Search Console. The path restriction lifts, by Google's own wording. You also get per-sitemap discovery counts, which makes the Sitemaps report a diagnostic instead of a checkbox. The cost is that a new shard is a manual step someone has to remember.
- Publish the shards at the root. A route handler at
/sitemap-listings-0.xmlsits at the root, covers everything, and needs no human in the loop. You give up the file convention and write the XML by hand.
Pick one. Doing neither means the shard is technically live, technically valid, and technically ignored.
While you are in there, check hosts. Every URL in a sitemap must come from a
single host — a file on example.com cannot vouch for directory.example.com.
Google's crawling infrastructure agrees from the other direction: it
defines a site as a unique hostname,
so a directory on a subdomain is a separate site with its own crawl budget and
needs its own sitemap either way.
lastmod is where file-based sites start lying
The protocol is unambiguous about what the date means: "the date the linked page was last modified, not when the sitemap is generated." Google adds a condition: it uses the value when the value is consistently and verifiably accurate, checked against the page's actual last modification. The bar for "modified" is a change to main content, structured data or links. A bumped copyright year doesn't qualify.
Here is how a Next.js site breaks that without anyone writing a bug. Content lives in MDX files, so the obvious source of truth is the file's modification time:
// app/sitemap.ts — read 13 September 2026
async function fileMtime(filePath: string, fallback: Date): Promise<Date> {
try {
const stat = await fs.stat(filePath)
return stat.mtime
} catch {
return fallback
}
}That is the helper in this site's own app/sitemap.ts, and on a laptop it is
correct. In CI it is not. Git does not record modification times, so a fresh
clone stamps every file with the moment of checkout — which means every page in
the sitemap claims it changed at build time, on every build. Ship twice a week
and you have told Google your entire archive was rewritten a hundred times a
year.
The fixes are cheap. Knowing to look is the hard part:
- For file-backed content, read the date from frontmatter, or ask git for it
with
git log -1 --format=%cI -- <path>during the build. - For database-backed listings, use the row's
updated_at— and make sure view counters, click counters and cache warmers don't touch that column. A page whose body is identical should not be advertised as modified because someone looked at it. - Hold the same line on the index file. Its
lastmodis the time that shard changed, not the time the build ran.
An unreliable lastmod is worse than none at all, because Google's stated
condition for using it is consistency. Break that and you lose the signal for
the pages where it would have mattered.
Which URLs belong in there at all
A directory sitemap should contain canonical, indexable, 200-returning URLs and nothing else. Three categories reliably sneak in.
Pages you deliberately made noindex. DirectoryLaunch renders
category-and-city combinations below minListingsToIndex (default: three
listings) but marks them noindex, which keeps thin city-swap pages out of the
index. Those URLs must not appear in the sitemap, or you are asking for a crawl
and refusing an index in the same breath. This site does the same thing with
thin tag pages, in the sitemap builder itself:
const blogTagPages = blogTags
.filter(({ count }) => count >= THIN_TAG_THRESHOLD)
.map(({ tag, lastPostDate }) => ({ /* ... */ }))Redirects and dead listings. A directory deletes rows. If the sitemap still carries them, Googlebot spends fetches confirming what you already know. Return 404 or 410 for removed listings and drop them from the query that feeds the sitemap in the same migration.
Filter URLs. Category × city × price × sort is a URL factory, and the canonical is almost never the filtered view. Keep them out.
One caveat on the framing, because it gets overstated: trimming a sitemap does not hand crawl budget back to the rest of your pages. Google says so directly, and we went through why in Discovered — currently not indexed. The sitemap delivers the URLs you have already decided are worth showing, and that is the whole of its job.
Submitting it is a hint, and the queue is shared
Worth keeping in view while you tune all of this: Google's wording on submission is "merely a hint: it doesn't guarantee that Google will download the sitemap or use the sitemap for crawling URLs on the site." A clean file buys you a good chance at a well-aimed crawl. That is the entire warranty.
The filing cabinet moved, too, and the move says something. In November 2025 Google opened a separate crawling-infrastructure site on the grounds that its crawlers are "shared across a variety of Google products beyond Search, including Google Shopping, News, Gemini, AdSense, and more," and that December it relocated the crawl-budget and faceted-navigation guides there as documentation "more relevant to many Google products that use Google's crawlers, not just Search." The guide that landed there says the crawl capacity limit "is shared across all crawlers," so demand from one reduces what is available to the others.
For a directory that matters in a specific way. Your listing pages are exactly
the kind of structured, frequently-updated inventory that several Google
products want at once, and they all draw from one pool of connections to your
origin. A slow database query on a city page now shows up as a ceiling on every
Google surface that fetches you, Search included. Shard size, response time and
an honest lastmod all buy fetches back out of that shared pool.
What to do this week
Four passes, roughly an hour, in this order:
- Fetch your own sitemap and count. If you are under 50,000 URLs, stop reading about shards; your problem is elsewhere and probably upstream, in how many pages you publish that nobody wants.
- Diff three
lastmodvalues against reality. Pick three listings you know have not been touched in months. If their dates say today, your pipeline is stamping build time, and that is the first thing to fix. - Check the parent-directory rule against your actual slugs. This is a two-minute check with the biggest payoff on the list, because a sitemap that fails it fails silently.
- Open the Sitemaps report and read the discovered count. Submitted versus discovered tells you whether Google parsed the file. Discovered versus indexed is a different conversation, and a longer one.