Next.js Edge Functions Cheat Sheet

Middleware, API routes, and caching at the edge

Place logic closer to users with middleware, edge API routes, and cache control. Quick reference guide with examples and best practices. Updated November 2025.

Last Updated: November 21, 2025

Focus Areas

Focus
Use middleware for auth checks and redirection at the edge
Enable caching headers to reuse responses safely

Commands & Queries

npx next dev
Run the Next.js dev server
export const config = { runtime: 'edge' }
Mark functions for the edge
cache-control: public, max-age=60
Tune caching headers

Summary

Ship edge-friendly routes and caches by keeping functions small and pure.

💡 Pro Tip: Avoid blocking code and keep edge functions lean.
← Back to Web Frameworks | Browse all categories | View all cheat sheets