In Next.js, Server Components are rendered entirely on the server. This approach supports both SSR (Server-Side Rendering) and SSG (Static Site Generation), offering enhanced performance, improved SEO, and flexible caching compared to client-side fetching.
Server-Side Only
window
or localStorage
are unavailable.console.log
outputs appear in server logs, not in the browser's DevTools.Rendering Methods
Caching Strategies
{ cache: "no-cache" }
to control caching.fetch(..., { next: { revalidate: 10 } })
to implement ISR or reduce redundant fetch calls.The following example demonstrates a Server Component that fetches data before rendering:
// app/dashboard/page.tsx
export default async function Dashboard() {
// Customize caching as needed.
const res = await fetch("<https://api.example.com/data>", { cache: "no-cache" });
const data = await res.json();
return (
<section>
<h1>Data: {data.title}</h1>
</section>
);
}
Static Rendering or SSR:
Ideal for pages that need data to be available at the initial render.
Better SEO:
Fully rendered HTML improves indexing and search visibility.
Reduced Frontend Load:
Data is pre-fetched on the server, eliminating additional client-side fetch calls.