Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Best practices · Stacks and tools

Next.js App Router Best Practices

Opens with credits

A current guide to building with the Next.js App Router, checked against the Next.js 16.4 docs. It covers Server and Client Components, the Cache Components model with use cache, securing Server Actions, proxy.ts, metadata, images and keeping your app up to date.

Written by Tauseef Fayyaz7 chapters, 33 practicesAbout 20 min27 quiz questionsReviewed 12 October 2026

What you will learn

7 chapters · about 20 min

  1. 1Server and Client ComponentsWhere your code runs decides your bundle size, your security and your speed. These practices keep most work on the server and the browser bundle small.5 practices · 4 min
  2. 2Caching with Cache ComponentsNext.js 16 replaced implicit caching with an explicit, opt-in model. This chapter shows how to turn it on, what to cache, and how to refresh it.6 practices · 4 min
  3. Securing Server Actions and data accessServer Actions are public HTTP endpoints, even when they feel like local functions. These practices are taken from the official Next.js data security guide.5 practices · 3 minOpens with credits
  4. Routing, proxy.ts and error handlingHow to use the file conventions for loading and error states, and how to use proxy.ts, the renamed middleware, without making it a bottleneck.4 practices · 2 minOpens with credits
  5. Metadata and SEOHow to give every page a correct title, description, social image and sitemap entry using the built-in Metadata APIs.4 practices · 2 minOpens with credits
  6. Images, fonts and bundle sizePractical settings for next/image and next/font, and how to keep the JavaScript you ship small.5 practices · 3 minOpens with credits
  7. Configuration, environment and upgradesHabits that keep a Next.js project secure and current: environment variables, the React Compiler, and upgrading on a schedule.4 practices · 2 minOpens with credits

About this guide

These Next.js App Router best practices are written for Next.js 16.4, the current release as of October 2026. A lot of older Next.js advice no longer applies: middleware is now proxy, request APIs like params and cookies are async, and caching has moved to an explicit, opt-in model called Cache Components, built on the use cache directive. Following a 2024 tutorial today will lead you to deprecated APIs.

Every practice here is checked against the official nextjs.org documentation. The big ideas are simple. Render on the server by default and send only small interactive islands to the browser. Decide what to cache on purpose, with use cache and cacheLife, and stream everything else behind Suspense. Treat every Server Action as a public endpoint and check the user inside it.

Start with the first two chapters: Server Components and caching shape every page you build, and getting them right fixes most slow pages and surprise server bills. The later chapters cover security, routing with proxy.ts, SEO metadata, images and fonts, and how to keep a Next.js project current.

If you are building your first Next.js project for a portfolio or internship, this guide is a good review list to run through before you share the link.

Common questions

Is middleware deprecated in Next.js 16?

Yes. The middleware file convention was deprecated in Next.js 16 and renamed to proxy. Rename middleware.ts to proxy.ts and the exported function to proxy, or run npx @next/codemod@canary middleware-to-proxy . to do it for you. Proxy runs on the Node.js runtime by default.

What is use cache in Next.js?

It is a directive that caches the return value of an async function or component. It is part of Cache Components, which you turn on with cacheComponents: true. Pair it with cacheLife to set how long the result stays fresh and cacheTag so you can refresh it after a change.

What is the difference between updateTag and revalidateTag?

updateTag expires cached data immediately, so the user sees their own change right away; it works only in Server Actions. revalidateTag(tag, 'max') uses stale-while-revalidate, serving old content while fresh content loads, and works in Server Actions and Route Handlers. Use the first after a user edit and the second for webhooks and background updates.

Are Next.js Server Actions secure?

They have useful defaults: they accept only POST, check the Origin header against the host, use encrypted action ids, and unused actions are removed from the build. They are still public endpoints that anyone can call directly, so you must check authentication, authorization and input inside every action.

Why is params a Promise in Next.js?

Since Next.js 15, request-specific APIs such as params, searchParams, cookies() and headers() are asynchronous, and Next.js 16 removed the old synchronous access. This lets Next.js prerender as much of the page as possible and only wait for request data where you actually await it.

What is the latest version of Next.js?

As of October 2026 the latest release is Next.js 16.4, published on October 6, 2026. It ships with React 19.3 and recommends Cache Components for every app. The Next.js team has said Cache Components will become the default in Next.js 17.

Sources (7)

Checked against these, last on 12 October 2026.

  1. Next.js 16.4, Next.js blognextjs.org/blog/next-16-4
  2. Caching, Next.js docsnextjs.org/docs/app/getting-started/caching
  3. Revalidating, Next.js docsnextjs.org/docs/app/getting-started/revalidating
  4. How to think about data security in Next.js, Next.js docsnextjs.org/docs/app/guides/data-security
  5. proxy.js, Next.js docsnextjs.org/docs/app/api-reference/file-conventions/proxy
  6. Metadata and OG images, Next.js docsnextjs.org/docs/app/getting-started/metadata-and-og-images
  7. Image Component, Next.js docsnextjs.org/docs/app/api-reference/components/image

Picked from the other libraries by shared topics.

Project structures

See all
Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com