Skip to content

Cloudflare Worker

A Worker in front of your site sends crawlers to Prebaked and everyone else to your origin. If Prebaked fails or takes over 5 seconds, crawlers get your origin page.

A Worker on your site's route. Crawlers (search engines, AI crawlers, link previews) get the page prerendered by Prebaked; visitors get your origin unchanged. Works with any origin behind Cloudflare.

What it does

  • Prerenders only GET / HEAD requests from a known crawler user agent. Static files (.js, .css, images, fonts, ...), other methods and requests carrying X-Prerender (Prebaked's own page fetches) go straight to your origin.
  • Calls GET https://service.prebaked.io/<full page URL> with your token in X-Prerender-Token.
  • Passes Prebaked's 200, redirects, 404 and 410 to the crawler (the page's own status).
  • Serves your origin page instead when Prebaked cannot be reached, takes longer than 5 seconds, or answers 401/403 (token or domain problem), 400 or 5xx. Crawlers never see a Prebaked error.
  • Sends Prebaked only the crawler's user agent, the token and the visitor IP, never cookies or credentials; a Set-Cookie from Prebaked is not passed on.

1. Copy the files

Into a Worker project (npm create cloudflare@latest, or an existing one):

  • src/worker.ts
  • src/prebaked-edge.ts (bot detection, service URL, fallback; no dependencies)
  • wrangler.toml (or merge its routes and [vars] into yours)

2. Configure

In wrangler.toml:

toml
main = "src/worker.ts"
routes = [{ pattern = "www.<your-domain>/*", zone_name = "<your-domain>" }]

[vars]
PREBAKED_SERVICE_URL = "https://service.prebaked.io/"

Store the token as a secret, not in wrangler.toml:

sh
npx wrangler secret put PREBAKED_TOKEN

3. Deploy

sh
npx wrangler deploy

Without PREBAKED_SERVICE_URL or PREBAKED_TOKEN the Worker passes every request to your origin.

4. Check it

sh
curl -A "Googlebot" https://www.<your-domain>/        # rendered HTML
curl https://www.<your-domain>/                      # your normal page

The first crawler request appears in the Prebaked dashboard request log.

Notes

  • The visitor IP (CF-Connecting-IP) is sent as X-Forwarded-For, so Prebaked can verify that a request claiming to be Googlebot really comes from Google.
  • The 5 second limit covers the whole Prebaked response. Cached pages answer well within it.

Start a 30-day free trial.

No card needed. Add and verify your domain, copy your token, paste it into the config above.

Start free trial