Pre-render dynamic routes, generateMetadata for SEO, on-demand generation.
The ultimate in-between state optimization is eliminating it entirely. Pre-rendered pages load instantly because there's nothing to wait for—the HTML is ready before the user even clicks.
generateStaticParams tells Next.js which dynamic route segments to pre-render at build time.
Return an array of params objects for each page to pre-render:
// app/[slug]/page.tsx
export async function generateStaticParams() {
const posts = await getPublishedPosts();
return posts.map(post => ({
slug: post.slug,
}));
}
export default async function PostPage({ params }) {
const { slug } = await params;
const post = await getPublishedPostBySlug(slug);
return <article>{post.content}</article>;
}At build time, Next.js generates HTML for each returned slug. When users navigate to these pages, content appears instantly.
Generate SEO metadata for each page:
export async function generateMetadata({ params }) {
const { slug } = await params;
const post = await getPublishedPostBySlug(slug);
return The generateMetadata function runs at build time for static pages, embedding the correct title and description in the HTML.
What about new posts created after build? Next.js handles this automatically—new slugs are generated on-demand when first requested, then cached.
To ensure pre-rendered pages update when content changes:
// In your Server Function after creating/updating a post
revalidateTag('posts', 'max');
revalidateTag(`post-${slug}`, 'max');
refresh();The combination ensures:
Pre-render pages that are:
Pages that read searchParams or need user-specific data should remain dynamic.