Netlify Edge Handlers enter Early Access

Netlify's Edge Handlers are now available in Early Access, and the company is taking sign-ups for access. The feature is best understood through a short snippet of JavaScript that runs at "the edge" — at the CDN level — on every request that passes through your site.

export function onRequest(event) {
  console.log(`Incoming request for ${event.request.url}`);
  event.replaceResponse(() => fetch("https://www.netlify.com/"));
}

In that example, the handler replaces the response outright with an Ajax request for a different URL — an odd result, but an illustration of the range on offer. Responses can be swapped for a manipulated version, including small tweaks like changing headers. A handler could also look up which user is logged in, fetch data on that user's behalf, and inject it into the response.

The Jamstack model has generally meant choosing between pre-rendering and pulling data on the client side. Edge Handlers add a third option: composing the response dynamically at the edge.

Netlify's take has one practical advantage — the handler code lives in the repository alongside the rest of your code, following the same pattern as Netlify's functions.