Skip to main content

    XML Sitemap

    An XML sitemap lists URLs you want search engines to discover. Prefer canonical and indexable URLs only.

    Definition

    An XML sitemap is a file that lists important URLs on your site to help search engines discover and crawl them efficiently. It doesn’t guarantee rankings, but improves discovery and coverage.

    Why it matters

    • Accelerates discovery and crawling of new pages, especially orphan pages
    • Helps large sites and pSEO sites manage indexing scope
    • Works with Search Console for monitoring index status and errors
    • Provides lastmod to signal content freshness to search engines
    • Supports extended markup for images, videos, and news content
    • Is a fundamental item in SEO technical audits
    • Helps multilingual sites differentiate URLs across language versions

    How to implement

    • Include only canonical + indexable URLs (avoid noindex, redirects, 404s, soft 404s)
    • Update lastmod only when content actually changes (avoid auto-refreshing dates)
    • Use sitemap index for large sites (max 50,000 URLs per sitemap)
    • Reference sitemap in robots.txt via Sitemap: directive
    • Regularly validate that all sitemap URLs return 200 status
    • Use gzip compression for large sitemaps (.xml.gz)
    • Automate sitemap generation in your CI/CD pipeline

    Examples

    xml
    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
      <url>
        <loc>https://example.com/</loc>
        <lastmod>2025-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
      </url>
      <url>
        <loc>https://example.com/products/widget</loc>
        <lastmod>2025-01-10</lastmod>
      </url>
    </urlset>
    javascript
    // Auto-generate sitemap (Node.js example)
    const { SitemapStream, streamToPromise } = require('sitemap');
    const { createWriteStream } = require('fs');
    
    const sitemap = new SitemapStream({ hostname: 'https://example.com' });
    const writeStream = createWriteStream('./public/sitemap.xml');
    
    sitemap.pipe(writeStream);
    sitemap.write({ url: '/', lastmod: new Date(), priority: 1.0 });
    sitemap.write({ url: '/blog', lastmod: new Date() });
    sitemap.end();

    Related

    FAQ

    Common questions about this term.

    Back to glossary