Next.js › Client Components & Hydration

How can you minimize the amount of JavaScript sent to the browser when using client components?

Advanced

Answer

You keep client components as small and focused as possible, pushing interactivity down to the smallest piece of the tree that actually needs it, rather than marking an entire page or large section as a client component just because one small part needs interactivity.
// Instead of making the whole page a client component,
// isolate just the interactive button
function ProductPage() {
  return (
    <div>
      <ProductDetails />
      <AddToCartButton />
    </div>
  );
}
Real-world example A product page keeps the description and images as server components and isolates only the small add to cart button as a client component, keeping most of the page's JavaScript footprint minimal.

Common follow-ups: How do you identify which parts of a page truly need to be client components?;What tools can measure how much JavaScript a page is sending to the browser?