How can you minimize the amount of JavaScript sent to the browser when using client components?
Short 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.
Advertisement
AModel 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.
Likely 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?
Related topics