Menu

1 / 2

Our sitemap hit 25 MB in 80 languages. Moving hreflang to the page head took it to 1 MB

DEV Community: nextjs·Pranav Ajay·about 10 hours ago
#oqSFDd7F
#devtonextjs#devto#dev#sitemap#languages
Reading 0:00
15s threshold

We run Saluvo , a health information site and app that is written in 80+ languages. The marketing pages, lab test explainers, symptom guides and blog posts each exist in many of those languages, which adds up to about 3,900 URLs.

A few weeks in, our sitemap.xml was 25 MB . Google's limit for a single sitemap is 50 MB uncompressed (and 50,000 URLs), so we were halfway to the ceiling with only a few thousand pages. Today the same sitemap lists 3,920 URLs in about 1 MB , and hreflang still works. Here's what happened and what we changed.

How a sitemap grows quadratically

Next.js (App Router) lets you return the sitemap as data from app/sitemap.ts , including language alternates for each URL. We used it the obvious way:

// app/sitemap.ts (before) export default function sitemap ( ) : MetadataRoute . Sitemap { return PAGES . flatMap ( ( path ) => LOCALES . map ( ( locale ) => ( { url : `${SITE}/${locale}${path}` , alternates : { languages : { . . . Object . fromEntries ( LOCALES .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.