Edge Functions declarations

Experimental Feature

This experimental feature is available to try out before it’s fully released or ready for production. We recommend using it in non-critical sites and non-production environments only. Learn more in our Netlify Labs doc.

Unlike regular Functions, Edge Functions aren’t automatically assigned a URL route for you to use as a function endpoint. Instead, you create declarations to configure your edge functions to run on specific URL patterns.

Each edge function declaration associates one site path pattern with one function to execute on requests that match the path. A single request can execute a chain of edge functions from a series of declarations. A single edge function can be associated with multiple paths across various declarations.

# Add a declaration

Declare your edge functions in netlify.toml using the edge_functions property. This maps glob-style routes to an array of functions that will run — in order — for any requests that match the routes.

[[edge_functions]]
  path = "/admin"
  function = "auth"

[[edge_functions]]
  path = "/admin"
  function = "injector"

[[edge_functions]]
  path = "/blog/*"
  function = "auth"

[[edge_functions]]
  path = "/blog/*"
  function = "rewriter"

[[edge_functions]]
  path = "/*"
  function = "common"

This example shows how both paths and functions can be configured across multiple declarations.

  • A request for /admin would invoke the auth function first, then injector, and finally common.
  • The auth function runs for the /admin path and any child paths of /blog.

# Declaration processing order

Keep the following considerations in mind when working with Edge Functions.

  • Your declarations in netlify.toml are processed before framework-generated declarations.
  • Routes are evaluated against netlify.toml declarations in order from top to bottom.
  • Edge functions declared for a path run before redirects declared for that path.
  • Note that any edge function declared for the target path of a rewrite will not execute for rewritten requests.

Experimental Feature

This experimental feature is available to try out before it’s fully released or ready for production. We recommend using it in non-critical sites and non-production environments only. Learn more in our Netlify Labs doc.