- Published on
TIL: a gitignored sitemap.xml is stale on every machine except the builder
- Authors

- Name
- Nadim Tuhin
- @nadimtuhin
I wrote a small script to tell IndexNow about every page on this site. It read public/sitemap.xml, found 93 URLs, and the API returned 200.
The live sitemap had 123.
The site generates sitemap.xml at build time, and *.xml is in .gitignore. So the file on disk is whatever my last local build produced. It was missing 30 pages, including every post I had written since then. A 200 from the API only meant it accepted the 93 I sent.
I only noticed because I compared the two counts before saying it was done:
curl -s https://www.nadimtuhin.com/sitemap.xml | grep -c '<loc>'
The fix was to stop reading the local file and fetch the live one:
const xml = await (await fetch(`https://${HOST}/sitemap.xml`)).text()
const urls = [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])
The second run sent all 123.
Anything that reads a generated, ignored file is reading a snapshot. If the live site is what matters, ask the live site.