On this page
A sitemap is an inventory of URLs you want search engines to discover, not a command to index every page. On a large resource hub, a careless inventory can advertise redirects, outdated filter pages, and drafts faster than anyone can inspect them.
The practical goal is a predictable generation pipeline. You will define which URLs qualify, partition the inventory sensibly, generate valid XML, and compare the published sitemap with the pages your application actually serves.
Define the eligible URL set first
Start with a canonical inventory from your content system. Include published pages that are intended for indexing, resolve successfully, and represent the preferred version of their content. Exclude draft previews, internal search results, redirects, and duplicate tracking URLs. Sitemap membership should follow editorial and routing rules, not whatever links a crawler happened to encounter.
Inspect a sample using the Sitemap URL Extractor. The Sitemap URL Extractor below helps turn XML into a reviewable URL list. Use that list to spot inconsistent hosts, obsolete path prefixes, or accidental parameters before investigating more complex crawling issues.
Define one preferred origin and a consistent trailing-slash policy. If the application redirects from one URL shape to another, publish the final form in the sitemap. This reduces unnecessary requests and makes later comparisons less ambiguous. A sitemap can support canonical signals, but it cannot override contradictory redirects, internal links, or page-level directives.
Document exceptions such as multilingual equivalents or separately indexable documentation versions. These cases deserve explicit rules rather than blanket parameter removal. The important distinction is intentional variation versus accidental duplication, and only the content model can reliably make that decision.
Partition for limits and operational clarity
A standard sitemap supports up to 50,000 URLs and 50 MB of uncompressed data. Use multiple files when either limit would be exceeded. Compression can reduce transfer size, but it does not change the uncompressed limit. Leave some headroom so an ordinary content import does not unexpectedly break generation.
A sitemap index references the individual files. Group those files by meaningful sections such as articles, tools, and downloadable resources, then shard large groups using stable identifiers or deterministic batches. This provides diagnostic boundaries: an issue affecting the article sitemap is easier to isolate than one mixed across every content type.
Google's sitemap construction guidance covers supported formats and requirements. Use those rules as the baseline rather than copying an old plugin configuration. Do not create thousands of tiny sitemaps merely because each category has a separate landing page.
Stable partitioning also reduces unnecessary churn. If every new article moves all later URLs into different files, cache invalidation and change review become noisy. Prefer a scheme where adding content changes only a small portion of the inventory. Deterministic ordering makes output comparisons useful and simplifies automated tests.
Generate XML from trusted content records
Generate sitemap entries from the same published records that drive public routes. Do not maintain a second hand-edited URL list unless the site is genuinely small and static. Separate URL eligibility from XML serialization so each part can be tested independently.
This simplified JavaScript example shows serialization after eligibility filtering. Production implementations should also validate host ownership, enforce file-size limits, and publish shards through a controlled release process.
const escapeXml = (value) => String(value).replace(
/[<>&"']/g,
(char) => ({
"<": "<", ">": ">", "&": "&",
'"': """, "'": "'"
})[char]
);
const entries = records
.filter((record) => record.published && record.indexable)
.map((record) => {
const loc = escapeXml(new URL(record.path, origin).href);
const modified = record.contentModifiedAt;
const lastmod = modified
? "<lastmod>" + escapeXml(modified) + "</lastmod>"
: "";
return "<url><loc>" + loc + "</loc>" + lastmod + "</url>";
});
const xml = '<?xml version="1.0" encoding="UTF-8"?>' +
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' +
entries.join("") + '</urlset>';Use a real XML parser in tests rather than checking only for opening and closing strings. The serializer must escape XML-sensitive characters, while the URL builder must encode URL components appropriately. These are different responsibilities. Avoid double-encoding a URL simply because both stages need validation.
Use modification dates that mean something
A useful lastmod value reflects a significant update to the page, not the time a build job ran. Replacing every timestamp on every deployment makes the field less informative. Track meaningful content changes in the publishing system and omit lastmod when you cannot provide a trustworthy value.
Define what counts as significant for your content. Updating a tutorial's instructions, adding a substantial section, or changing key product information may qualify. A sitewide footer edit usually should not make every article appear newly revised. Keep the rule consistent so the date retains editorial meaning.
Google's sitemap overview explains that sitemaps help discovery but do not guarantee crawling or indexing. Avoid promising that fresh timestamps force immediate recrawls. A page still needs accessible content, sensible internal linking, and a coherent indexing policy.
For generated collections, choose a date based on the collection's actual content change rather than the newest unrelated database event. If you cannot determine a meaningful date cheaply and reliably, omission is better than fabricated precision. Trustworthy metadata is more valuable than a field populated on every row.
Validate the released inventory continuously
Run the URL extraction tool against released files, not only a local candidate. Check duplicate URLs, unexpected origins, fragment identifiers, and paths that should have been removed. Then sample response codes and canonical declarations from each partition.
Use automated assertions for invariants: all locations use the preferred origin, all entries are unique, and every referenced sitemap exists. A full response check may be expensive on a large site, so combine deterministic build checks with a rotating production sample. Investigate failures before removing URLs indiscriminately.
Review Google's canonicalization guidance when the sitemap and indexed URL disagree. Compare redirects, canonical tags, and internal links before assuming the XML file is responsible. The sitemap is one signal within a broader system.
Connect this audit to your performance and SEO workflow and responsive image pipeline where resource pages depend on generated media. Keep a release record with entry counts and file sizes so a sudden inventory drop is visible before it becomes a discovery problem.
Key takeaways
- Build a canonical inventory from published, indexable records rather than indiscriminate crawling.
- Respect URL and uncompressed-size limits while partitioning by useful operational boundaries.
- Generate escaped XML deterministically and parse the result in automated tests.
- Publish meaningful modification dates, or omit them when the source data is unreliable.
- Validate released files and sample actual page responses, not just local output.
- Treat sitemaps as discovery signals, supported by consistent routes, internal links, and indexing directives.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor