Skip to content
Dashboard

Vercel Edge Middleware: Dynamic at the speed of static (historical)

High-performance compute for routing, experimentation, and more.

Link to headingWhat is Vercel Routing Middleware?

Edge Middleware runs before the Edge Network Cache, for fast rewrites and redirectsEdge Middleware runs before the Edge Network Cache, for fast rewrites and redirects
Edge Middleware runs before the Edge Network Cache, for fast rewrites and redirects

Link to headingWhy Routing Middleware?

We've been using Edge Middleware to drive experiments and personalization on our marketing surfaces. We keep our ability to customize our content workflows while keeping the performance that Next.js on Vercel gives us.
Jon Eide Johnsen Growth Manager at Sanity.io

Link to headingExperiment at the edge

A/B testing and feature flags, directly in your code with Edge MiddlewareA/B testing and feature flags, directly in your code with Edge Middleware
A/B testing and feature flags, directly in your code with Edge Middleware
With Edge Middleware, we can show the control or experiment version of a page immediately instead of using third-party scripts. This results in better performance and removes the likelihood of flickering/layout shifts.”
Jillian Anderson Slate Software Engineer at SumUp

Link to headingLocalize at the edge

Personalize content based on geolocation headers with Edge MiddlewarePersonalize content based on geolocation headers with Edge Middleware
Personalize content based on geolocation headers with Edge Middleware
The API for Middleware is pretty intuitive, it allows developers to build features without worrying too much about framework-specific details since it conforms to the same standard that browsers use for requests and responses.
Dylan Staley Software Engineer at HashiCorp

Link to headingAuthenticate at the edge

Authenticate and authorize at the edge, before the initial page loadAuthenticate and authorize at the edge, before the initial page load
Authenticate and authorize at the edge, before the initial page load

Link to headingAgility for all frameworks

Link to headingAPI routes and runtime choices

Link to headingEdge for all frameworks

export default function middleware(request) {
// Construct the url
const url = new URL(request.url);
// Only run the middleware on the home route
if (url.pathname === '/') {
// Store the country where will be redirecting
let country = request.headers.get('x-vercel-ip-country').toLowerCase();
// Update url pathname
url.pathname = `/${country}.html`;
// Return a new redirect response
return Response.redirect(url);
}
}

Edge Middleware can be added to any application, using any framework

Link to headingHow to get started


Ready to deploy?