Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn how to render a different page based on the User-Agent header.
User-Agent Based Rendering is a Next.js edge middleware template from the Vercel examples collection that demonstrates how to serve a different page to users based on the User-Agent request header.
This template is a minimal example that reads the User-Agent header from an incoming request and conditionally renders an alternative page depending on the detected client. It runs as Vercel Edge Middleware, meaning the decision is made at the network edge before the request reaches the server. The project is part of the official vercel/examples repository and uses Next.js as its framework. It is styled with Tailwind CSS, and it provides both a live demo and a one-click deployment option.
create-next-app for scaffolding and the React ecosystem.pnpm create next-app --example and run it with pnpm dev.The example's middleware reads the User-Agent header, compares it against a predetermined rule, and returns a response that renders one page or another. Because it runs on Vercel Edge Middleware, the check happens close to the user when deployed on Vercel. Locally, pnpm dev runs the same Next.js middleware in development mode.
Yes, the template is part of the public vercel/examples repository and its code is freely accessible for anyone to use and modify.
The User-Agent header is sent by every HTTP client and identifies the browser, operating system, or bot. This template uses that string to decide which page to render.
The middleware code is Next.js middleware, so it can run in any Next.js environment that supports middleware, though the example is optimized for deployment on Vercel's edge network.
Use pnpm create next-app --example pointing to the repository URL, then run pnpm dev to start the development server.
