IndexNow with Cloudflare Workers
Send IndexNow updates from a Cloudflare Worker using Secrets, waitUntil, and bounded retry behavior.
Store configuration safely
Bind the key as a Worker Secret. Keep host and keyLocation in environment configuration, and never return the key from an HTTP response.
Submit in the background
ctx.waitUntil(fetch('https://api.indexnow.org/indexnow', {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=utf-8' },
body: JSON.stringify({ host: env.HOST, key: env.INDEXNOW_KEY, keyLocation, urlList }),
}));Production safeguards
- Authenticate the trigger
- Verify the CMS webhook signature or protect the endpoint with service authentication.
- Bound the batch
- Validate host consistency and enforce the 10,000 URL maximum.
- Retry selectively
- Retry network failures and 429 responses with backoff, not permanent 400-series errors.
Serving the key file from the Worker
If your domain routes all traffic through Cloudflare Workers, you can serve the ownership key file directly from the Worker with an explicit text/plain header and cache control, avoiding origin round-trips.
if (url.pathname === `/${env.INDEXNOW_KEY}.txt`) {
return new Response(env.INDEXNOW_KEY, {
headers: {
"Content-Type": "text/plain; charset=utf-8",
"Cache-Control": "public, max-age=3600",
},
});
}Queueing and deduplication at the edge
- Batch with Cloudflare Queues or Cron Triggers
- Buffer publish webhooks and flush grouped same-host batches every few minutes to avoid 429 throttling.
- Disable Bot Fight challenges on the key path
- Ensure WAF rules allow automated GET requests to /<key>.txt without JavaScript challenges.