Skip to content

IndexNow with Next.js

Publish an IndexNow key in Next.js and submit changed URLs from a trusted server-side deploy hook.

Publish the key

Place KEY.txt in public/ so the deployed site serves it from the hostname root. Keep the submission secret in server-only environment configuration, not client bundles.

Submit from trusted code

await fetch('https://api.indexnow.org/indexnow', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json; charset=utf-8' },
  body: JSON.stringify({ host, key, keyLocation, urlList }),
});

Deployment workflow

Calculate changes
Compare the previous and current sitemap or use CMS webhook payloads.
Group by host
Build one payload for each exact hostname.
Log safely
Record status and counts, never the key or private draft URLs.

Middleware and i18n exclusions

In Next.js App Router projects using next-intl or custom auth middleware, ensure your matcher skips static .txt files in public/ so https://example.com/<key>.txt serves directly without locale prefixes or redirects.

export const config = {
  matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
};

Recommended CI/CD deploy hook flow

Diff the live sitemap after deploy
Compare the pre-deploy and post-deploy sitemap.xml to collect only added or modified URLs.
Run server-side after health check
Trigger the POST request only after the new deployment passes smoke checks so crawlers fetch fresh pages.