Need integration help? Contact our engineering team
Please choose the option as per your server configuration from the side menu and follow the instructions

Netlify Edge Functions Integration

Optimize your Netlify site for search engines and AI bots by running Index Render at the Edge. Edge Functions intercept traffic before it reaches your server, ensuring bots see fully pre-rendered HTML instantly.

Edge Performance Netlify Edge Functions run on Deno deploy, providing low-latency bot detection and content injection across Netlify's global network.
1

Create Edge Function

Create a file named indexrender.js inside your project's netlify/edge-functions/ directory.

indexrender.js
/**
 * IndexRender Netlify Edge Function
 * 
 * This function intercepts crawler requests and serves 
 * pre-rendered HTML to improve SEO and AI discoverability.
 */

export default async (request, context) => {
  // 1. Only process GET and HEAD requests
  if (request.method !== "GET" && request.method !== "HEAD") {
    return context.next();
  }

  // 2. Check if the request accepts HTML
  const acceptHeader = request.headers.get("accept") || "";
  if (!acceptHeader.includes("text/html")) {
    return context.next();
  }

  try {
    // 3. Load your API key from Netlify Environment Variables
    const apiKey = Deno.env.get("INDEX_RENDER_API_KEY");

    if (!apiKey) {
      console.warn("INDEX_RENDER_API_KEY is missing. Skipping pre-rendering.");
      return context.next();
    }

    // 4. Set up headers to forward to the IndexRender API
    const forwardedHeaders = {
      "x-indexrender-key": apiKey,
      "accept": "text/html",
      "user-agent": request.headers.get("user-agent") || "",
      "referer": request.headers.get("referer") || "",
      "x-original-host": request.headers.get("host") || "",
      "accept-language": request.headers.get("accept-language") || "",
    };

    // 5. Fetch the pre-rendered content
    const prerenderResponse = await fetch(
      `https://api.indexrender.io/api/v1/render?url=${encodeURIComponent(request.url)}`,
      {
        method: "GET",
        headers: forwardedHeaders,
      }
    );

    // 6. Handle cases where pre-rendering isn't needed
    if (prerenderResponse.status === 304 || prerenderResponse.status === 204) {
      return context.next();
    }

    const contentType = prerenderResponse.headers.get("content-type") || "";

    // 7. Serve the pre-rendered HTML to the bot
    if (prerenderResponse.ok && contentType.includes("text/html")) {
      return new Response(prerenderResponse.body, {
        status: 200,
        headers: {
          "content-type": "text/html; charset=utf-8",
          "x-prerender-source": "indexrender",
          "cache-control": "public, max-age=300, stale-while-revalidate=600",
        },
      });
    }
  } catch (error) {
    // Always fall back to the normal site flow if an error occurs
    console.error("IndexRender Edge Function error:", error);
  }

  return context.next();
};

// Configure the Edge Function to run on all paths
export const config = {
  path: "/*",
};
2

Add API Key to Netlify

Configure your API key in the Netlify dashboard to authenticate the Edge Function securely.

  1. Go to your site's dashboard in Netlify.
  2. Navigate to Site configuration > Environment variables.
  3. Add a new variable with the key:
INDEX_RENDER_API_KEY = your_api_key_here
3

Verify Integration

To confirm that your integration is active, send a request to your URL while simulating a search engine bot. Run the following command in your terminal:

Terminal
curl --location 'https://yourdomain.com' \
--header 'User-Agent: googlebot'

In the <head> section of the response, you should see the Index Render metadata tags indicating the page was successfully pre-rendered:

Expected Output
<!--IndexRender-->
<meta name="generator" content="IndexRender/65d6cde" />
<meta name="x-rendered-by" content="IndexRender/65d6cde" />
<meta name="x-rendered-at" content="2026-04-26T18:26:03.1076251Z" />
<meta name="x-render-traceparent" content="00-39f1dd04eeba1243cae01dc5c70e5b47-cdf5cfae992740d8-01" />