Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
By A/B testing at the edge, you'll reduce CLS from client-loaded experiments and improve your site's performance with smaller JS bundles.
A/B Testing Simple is a Vercel example template built on Next.js that runs A/B tests in Edge Middleware, serving statically generated variants at the edge to eliminate client-side layout shift.
A/B Testing Simple is an open-source Next.js example from Vercel that demonstrates how to perform A/B testing using Edge Middleware. It accepts incoming requests through a middleware.ts file and returns one of several pre-rendered page variants, with no client-side JavaScript required to swap content. The template uses Tailwind CSS for styling and is part of the vercel/examples repository on GitHub, which currently has over 5,000 stars.
pnpm create next-app and run it with pnpm dev for development, then deploy to Vercel.The template places all experiment logic in a middleware.ts file that executes on Vercel's Edge Network. At request time, the middleware evaluates which variant a visitor should see and serves the corresponding statically generated page, avoiding any client-side rendering of the alternative content. The demo is live at edge-functions-ab-testing-simple.vercel.app.
Other Vercel example templates in the same category include ab-testing-google-optimize and ab-testing-statsig. These also use edge middleware for A/B testing but integrate with Google Optimize and Statsig, respectively, rather than the hand-rolled approach shown here.
The template is open source and part of the public vercel/examples repository, so cloning it is free. Deploying it to Vercel uses your Vercel account; the template itself has no licensing fee.
You can deploy it in one click using the Vercel Deploy button, which clones the repository and sets up your project, or clone it locally with pnpm create next-app and run pnpm dev for development before deploying.
Client-side testing inserts experiment variants into the DOM after the page loads, which can cause layout shift and requires extra JavaScript. This template serves the variant as static HTML from the edge, eliminating layout shift and keeping the browser bundle smaller.
