🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
SEO••By Komal Nakrani

Astro IndexNow: Ping Bing When Pages Change

Submit Astro pages with IndexNow: host a key file in public/, post changed URLs from the built sitemap after each deploy, and which search engines take part.

#Astro#SEO#IndexNow#Bing

To use IndexNow with Astro, put a key file such as public/<your-key>.txt in your project, deploy, and then send changed URLs to https://api.indexnow.org/indexnow in a JSON POST after each deploy. Bing, Yandex, Seznam, Naver and other participating engines share submissions with each other. Google does not use IndexNow, so keep your sitemap and Search Console setup as well.

Key Takeaways

  • The key file proves you own the host; it contains only the key and sits at the site root.
  • Submit after the deploy finishes, never during the build, or engines may fetch old pages.
  • Send only URLs that changed; the built sitemap’s lastmod dates make that easy.
  • One request can carry up to 10,000 URLs for the same host.

Create and host the key

Generate a key of 8 to 128 letters, numbers or dashes:

# Terminal
KEY=$(openssl rand -hex 16)
echo "$KEY" > "public/$KEY.txt"
echo "$KEY"

The file must contain the key and nothing else. After deploying, https://www.example.com/<key>.txt should return it. Astro copies public/ to the build root as is; the folder structure docs show where public/ lives.

A submit script

This script reads the built sitemap, picks URLs whose lastmod is recent, and posts them. It needs Node.js 22.23.4 or newer, the same as current Astro releases, and uses only built-in modules:

// scripts/indexnow.mjs
import { readFile } from 'node:fs/promises';

const HOST = 'www.example.com';
const KEY = process.env.INDEXNOW_KEY;
const DAYS = Number(process.env.INDEXNOW_DAYS ?? 2);

if (!KEY) throw new Error('Set INDEXNOW_KEY');

const xml = await readFile('dist/sitemap-0.xml', 'utf8');
const cutoff = Date.now() - DAYS * 24 * 60 * 60 * 1000;
const urls = [...xml.matchAll(/<url><loc>([^<]+)<\/loc>(?:<lastmod>([^<]+)<\/lastmod>)?/g)]
  .filter(([, , lastmod]) => lastmod && Date.parse(lastmod) >= cutoff)
  .map(([, loc]) => loc);

if (urls.length === 0) {
  console.log('IndexNow: nothing changed');
  process.exit(0);
}

const res = await fetch('https://api.indexnow.org/indexnow', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json; charset=utf-8' },
  body: JSON.stringify({
    host: HOST,
    key: KEY,
    keyLocation: `https://${HOST}/${KEY}.txt`,
    urlList: urls.slice(0, 10000),
  }),
});

console.log(`IndexNow: ${res.status} for ${urls.length} URLs`);
if (!res.ok) process.exit(1);

The regular expression matches the compact XML that @astrojs/sitemap writes. It relies on per-URL lastmod dates; the sitemap lastmod tip shows how to add real ones. If your site has more than one sitemap file, loop over every sitemap-N.xml.

Run it after the deploy

The script should run once the new version is live. In GitHub Actions, add it as the last step of your deploy job:

# .github/workflows/deploy.yml (excerpt)
- name: Deploy
  run: npx wrangler pages deploy dist --project-name=example
  env:
    CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: IndexNow
  run: node scripts/indexnow.mjs
  env:
    INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }}

A 200 or 202 status means the submission was received. 403 usually means the key file was not found or does not match, and 422 means a URL does not belong to the host. Our GitHub Actions guide covers the rest of the workflow.

Cloudflare Crawler Hints

If your domain is proxied through Cloudflare, Crawler Hints can send IndexNow signals for you when cached content changes. Turn it on under Caching, Configuration. It needs no key file, but you lose control over which URLs are submitted. Use one approach, not both, so the same URLs are not reported twice.

IndexNow complements, not replaces, a sitemap. Keep sitemap-index.xml submitted in Bing Webmaster Tools and Google Search Console; the Search Console tip walks through setup. Any static theme from our catalog works with this script unchanged.

FAQ

Does Google support IndexNow?

No. Google does not take part in IndexNow. Use a sitemap and Search Console for Google, and IndexNow for Bing and the other participating engines.

Do I need to submit to every search engine separately?

No. Engines that support IndexNow share submitted URLs with each other, so one request to api.indexnow.org or any participating endpoint is enough.

Should I submit every URL on every deploy?

No. Submit only new, updated or deleted URLs. Repeatedly sending unchanged URLs does not speed up crawling.

Can I submit deleted pages with IndexNow?

Yes. Submit the URL after it starts returning 404 or 410, so engines recrawl it and drop it from their index.