Skip to content

Netlify Edge Function

A Netlify Edge Function sends crawlers to Prebaked and everyone else to your site. If Prebaked fails or takes over 5 seconds, crawlers get your normal page.

An Edge Function on every path of your Netlify site. Crawlers (search engines, AI crawlers, link previews) get the page prerendered by Prebaked; visitors get your site unchanged.

What it does

Same rules as the Cloudflare Worker:

  • Prerenders only GET / HEAD requests from a known crawler user agent. Static files, other methods and requests carrying X-Prerender go to your site.
  • Calls GET https://service.prebaked.io/<full page URL> with X-Prerender-Token.
  • Passes Prebaked's 200, redirects, 404 and 410 to the crawler.
  • Serves your normal page (context.next()) when Prebaked cannot be reached, takes longer than 5 seconds, or answers 401/403, 400 or 5xx.

1. Copy the files

Into your site repository, keeping the paths:

  • netlify/edge-functions/prebaked.ts (the function; config.path is /*)
  • netlify/lib/prebaked-edge.ts (bot detection, service URL, fallback; no dependencies)

2. Set the environment variables

In the Netlify UI (Site configuration > Environment variables) or with the CLI:

sh
netlify env:set PREBAKED_SERVICE_URL https://service.prebaked.io/
netlify env:set PREBAKED_TOKEN <your token> --secret

Without either variable every request goes to your site.

3. Deploy and check

Deploy as usual, then:

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 (context.ip) is sent as X-Forwarded-For so Prebaked can verify crawler IPs.
  • Imports use the .ts extension, as Deno (the Edge Functions runtime) requires.

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