A sitemap for a static site: generated, honest and short
Generate the sitemap from the same data as the pages, list only URLs that return 200 and should be indexed, and leave out every page that says noindex.
A sitemap is a list of the pages you want indexed. On a static site, the mistake is maintaining it by hand, and the second mistake is listing pages you do not actually want indexed.
Generate it from the same data as the pages
Our pages are built from a list of skills and a list of posts. The sitemap script reads the same lists after the build, so a new post appears in the sitemap in the same deploy that publishes it, and a draft never appears at all.
What to leave out, and why
| Page | Why it is not listed |
|---|---|
| Checkout hand-off | A person mid-flow, not a search result. Marked noindex |
| Order complete | Means nothing out of context. Marked noindex |
| 404 | A soft 404 in the index is worse than none |
| Any redirecting URL | Google indexes the destination, not the redirect |
The meta robots tag and the sitemap must agree. A page in the sitemap that says noindex is a contradiction, and contradictions are how pages end up in limbo.
List the URL the server answers
Every <loc> should be the exact URL that returns 200, including the trailing slash if your host serves one. Get that wrong and every other rule here stops mattering, as we found out in the trailing slash that kept our pages out of Google. Once it is right, submit it once in Search Console.
Questions
Which pages should not be in a sitemap?
Anything marked noindex, anything that redirects, checkout and thank-you pages, and error pages. A sitemap that lists a page the page itself refuses sends Google mixed signals.
Do priority and changefreq matter?
Google has said it largely ignores them. lastmod helps when it is accurate. Correct URLs matter far more than either.
How should a static site generate its sitemap?
In the build, from the same source data the pages are built from, so a new product or post cannot be missing from it and a deleted one cannot linger.