Server first, static where possible
Render on the server by default, keep routes static unless they must be dynamic, stream slow parts, and make caching explicit with revalidation and tags.
- ComponentsServer vs client and the boundary.
- RenderingStatic, dynamic, ISR and streaming.
- Cachinguse cache, fetch options, tags and router cache.
Rendering and caching are where Next.js interviews get serious — and where the framework changed most between versions. Explain the server/client boundary clearly, choose static or dynamic per route, and know how to revalidate.
1. Server Components vs Client Components?
Components are Server Components by default: they render on the server, can be async, read databases and secrets directly and send no JavaScript for themselves. Add 'use client' to make a component (and what it imports) a Client Component — needed for state, effects, event handlers and browser APIs. Push client components to the leaves of the tree.
// Server Component (default): data on the server, zero JS for this part
export default async function CoursePage({ params }) {
const { slug } = await params;
const course = await db.course.findUnique({ where: { slug } });
return (
<>
<h1>{course.title}</h1>
<LikeButton courseId={course.id} /> {/* client component for interactivity */}
</>
);
}
// like-button.tsx
'use client';
export function LikeButton({ courseId }) {
const [liked, setLiked] = useState(false);
return <button onClick={() => setLiked(!liked)}>{liked ? '♥' : '♡'} Like</button>;
}2. Static vs dynamic rendering — what decides which one a route gets?
A route is static (rendered at build or revalidation time, served from cache) unless it uses something only known per request: cookies(), headers(), searchParams, uncached data, or connection(). Then it is dynamic (rendered per request). Static pages are fastest; use dynamic only where the content is personal or always fresh.
3. Explain SSG, ISR and SSR in App Router terms.
- SSG — static at build time (with
generateStaticParamsfor dynamic segments). - ISR — static, but regenerated in the background after a time (
export const revalidate = 3600) or on demand (revalidatePath,revalidateTag). - SSR — dynamic, rendered on every request.
// ISR: rebuild this page at most once an hour
export const revalidate = 3600;
// On-demand: after an admin edit
'use server';
import { revalidatePath } from 'next/cache';
export async function publishCourse(id) {
await db.course.update({ where: { id }, data: { published: true } });
revalidatePath('/courses');
}4. What is streaming and how do Suspense boundaries help?
Streaming sends HTML in chunks: the shell renders immediately and slower parts arrive when ready, each wrapped in a <Suspense> boundary (or covered by loading.tsx). Users see content sooner, and one slow query no longer blocks the whole page.
export default function Dashboard() {
return (
<>
<Header /> {/* immediate */}
<Suspense fallback={<ChartSkeleton />}>
<RevenueChart /> {/* streams in when its data resolves */}
</Suspense>
<Suspense fallback={<ListSkeleton />}>
<RecentOrders />
</Suspense>
</>
);
}5. What are Cache Components and the use cache directive?
In Next.js 16, Cache Components (enabled in config) make caching explicit: mark a component, function or page with 'use cache' to cache its result, control lifetime with cacheLife() and invalidate with tags via cacheTag(). Everything else is dynamic by default, and the static parts of a page are prerendered as a shell while dynamic parts stream (Partial Prerendering).
import { cacheLife, cacheTag } from 'next/cache';
async function getCourses() {
'use cache';
cacheLife('hours');
cacheTag('courses');
return db.course.findMany({ where: { published: true } });
}6. How does fetch caching work in the App Router?
Within one render, identical fetch calls are de-duplicated (request memoisation). Persistent caching of fetch results is opt-in in Next.js 15+ (the default is no caching): pass cache: 'force-cache' or next: { revalidate, tags }. Use tags to invalidate related data together with revalidateTag.
const res = await fetch('https://api.example.com/jobs', {
next: { revalidate: 600, tags: ['jobs'] }, // cache for 10 minutes, tagged
});7. What is the client-side Router Cache?
The browser keeps rendered route segments in memory during a session so back/forward navigation and revisits are instant. Layouts are reused; pages may be refetched depending on settings. After a mutation, router.refresh() or revalidation in a Server Action makes the client fetch fresh data.
8. How do you decide what to make a client component?
Only the parts that need interactivity or browser APIs — buttons, forms with local state, charts, maps. Keep data fetching and static content on the server. Pass server-rendered content into client components as children to avoid turning whole subtrees into client code.
Remember
Key points
- Server Components by default
'use client' only where needed.
- Request APIs make routes dynamic
cookies(), headers(), searchParams.
- Revalidate by path or tag
After mutations.
- Stream with Suspense
Slow parts do not block the page.
Interview drill
Follow-up questions
What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.
-
1 Can a Server Component use useState? Basic
No — hooks with state or effects need a Client Component.
-
2 Can you import a Server Component into a Client Component? Intermediate
Not directly; pass it as children or a prop from a Server Component parent.
-
3 What is the server-only package for? Intermediate
Importing
server-onlyin a module makes the build fail if that module is ever imported into client code — protecting secrets. -
4 What is Partial Prerendering? Advanced
Serving a static shell instantly from the edge while dynamic holes stream in the same response — static speed with dynamic content.
-
5 revalidatePath vs revalidateTag? Intermediate
revalidatePath clears cached data and output for a route; revalidateTag clears every cached entry with that tag across routes.
-
6 How do you force a route to be dynamic? Intermediate
Read a request API (cookies, headers), call
await connection(), or set route segment configdynamic = 'force-dynamic'in setups that use it.