Partial Prerendering
Partial Prerendering
Mixed rendering of static/dynamic content. An experimental feature in Next.js 14+.
Partial Prerendering
Mixed rendering of static/dynamic content. An experimental feature in Next.js 14+.
Partial Prerendering (PPR) is an experimental rendering strategy introduced in Next.js 14 that serves static content and dynamic content together on a single page. Previously, an entire page was rendered as either SSG (static) or SSR (dynamic), but PPR combines the two in a hybrid approach.
The core idea of PPR is the "Static Shell." Unchanging parts of the page such as the layout, navigation, and header are pre-rendered at build time and cached on a CDN, while dynamic parts such as user information, the shopping cart, and recommended products are filled in by streaming at request time. This achieves both the fast TTFB of static content and the personalization of dynamic content.
Technically, PPR makes use of React's Suspense and streaming. When a dynamic component is wrapped in Suspense, the static shell is sent first, and the dynamic part displays a loading UI and is then replaced by streaming once it is ready. Because this entire process happens within a single HTTP response, it provides a fast user experience without additional round trips.
PPR is particularly useful on e-commerce sites. The images, descriptions, and specs on a product detail page are rendered statically, while stock status, price, and the number of user reviews are fetched dynamically. This allows search engines to crawl the product information, and users can see the latest information in real time.
// === next.config.js - PPR νμ±ν ===
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
ppr: true, // Partial Prerendering νμ±ν
},
};
module.exports = nextConfig;
// === app/products/[id]/page.tsx - PPR μ μ© νμ΄μ§ ===
import { Suspense } from 'react';
import { ProductInfo } from './ProductInfo';
import { ProductPrice } from './ProductPrice';
import { ProductReviews } from './ProductReviews';
import { RecommendedProducts } from './RecommendedProducts';
// μ μ νλΌλ―Έν° μμ± (λΉλ μ)
export async function generateStaticParams() {
const products = await getProducts();
return products.map((product) => ({ id: product.id }));
}
// μ μ λ©νλ°μ΄ν°
export async function generateMetadata({ params }: { params: { id: string } }) {
const product = await getProduct(params.id);
return {
title: product.name,
description: product.description,
};
}
export default async function ProductPage({ params }: { params: { id: string } }) {
// μ΄ λ°μ΄ν° νμΉμ λΉλ μ μ€ν (μ μ λΆλΆ)
const product = await getProduct(params.id);
return (
<div className="product-page">
{/* μ μ λΆλΆ - λΉλ μ λ λλ§λμ΄ CDNμ μΊμ± */}
<header>
<h1>{product.name}</h1>
<ProductInfo product={product} />
</header>
{/* λμ λΆλΆ - μμ² μ μ€νΈλ¦¬λ° */}
<Suspense fallback={<PriceSkeleton />}>
<ProductPrice productId={params.id} />
</Suspense>
{/* μ μ λΆλΆ */}
<section className="description">
{product.description}
</section>
{/* λμ λΆλΆ - μ¬μ©μλ³ μΆμ² */}
<Suspense fallback={<RecommendationsSkeleton />}>
<RecommendedProducts productId={params.id} />
</Suspense>
{/* λμ λΆλΆ - μ€μκ° λ¦¬λ·° */}
<Suspense fallback={<ReviewsSkeleton />}>
<ProductReviews productId={params.id} />
</Suspense>
</div>
);
}
// === components/ProductPrice.tsx - λμ μ»΄ν¬λνΈ ===
// μ΄ μ»΄ν¬λνΈλ cookies() λλ headers()λ₯Ό μ¬μ©νλ―λ‘ λμ μΌλ‘ λ λλ§
import { cookies } from 'next/headers';
export async function ProductPrice({ productId }: { productId: string }) {
// cookies()λ₯Ό μ¬μ©νλ©΄ μλμΌλ‘ λμ λ λλ§μΌλ‘ μ ν
const userRegion = cookies().get('region')?.value || 'KR';
// μ§μλ³ κ°κ²© μ‘°ν (μ€μκ°)
const pricing = await fetch(
`https://api.example.com/pricing/${productId}?region=${userRegion}`,
{ cache: 'no-store' } // λμ λ°μ΄ν°
).then(res => res.json());
return (
<div className="price-section">
<span className="currency">{pricing.currency}</span>
<span className="amount">{pricing.amount.toLocaleString()}</span>
{pricing.discount > 0 && (
<span className="discount">{pricing.discount}% ν μΈ</span>
)}
<StockStatus available={pricing.inStock} />
</div>
);
}
// === components/RecommendedProducts.tsx - κ°μΈνλ μΆμ² ===
import { headers } from 'next/headers';
export async function RecommendedProducts({ productId }: { productId: string }) {
// headers()λ₯Ό μ¬μ©νλ©΄ μλμΌλ‘ λμ λ λλ§
const headersList = headers();
const userId = headersList.get('x-user-id');
const recommendations = await fetch(
`https://api.example.com/recommendations`,
{
method: 'POST',
body: JSON.stringify({ productId, userId }),
cache: 'no-store'
}
).then(res => res.json());
return (
<section className="recommendations">
<h2>μΆμ² μν</h2>
<div className="grid">
{recommendations.map((item: Product) => (
<ProductCard key={item.id} product={item} />
))}
</div>
</section>
);
}
// === μ€μΌλ ν€ μ»΄ν¬λνΈ (λ‘λ© μν) ===
function PriceSkeleton() {
return (
<div className="price-skeleton animate-pulse">
<div className="h-8 w-32 bg-gray-700 rounded" />
</div>
);
}
function RecommendationsSkeleton() {
return (
<section className="recommendations-skeleton">
<h2>μΆμ² μν</h2>
<div className="grid grid-cols-4 gap-4">
{[1, 2, 3, 4].map(i => (
<div key={i} className="h-48 bg-gray-700 rounded animate-pulse" />
))}
</div>
</section>
);
}
"My product page is built with SSG, but the price and stock need to be shown in real time. Do we have to switch the whole page to SSR?"
"You can use PPR (Partial Prerendering). Keep the static parts such as product information, images, and descriptions cached as SSG as they are, and just wrap the price and stock in Suspense to stream them dynamically. You can keep TTFB fast while still showing real-time data."
"What's the difference between PPR and the existing ISR?"
"ISR periodically regenerates the entire page, whereas PPR separates the static and dynamic parts within a single page. ISR shows every user the same cached page, but with PPR you can share the static shell while showing personalized dynamic content differently for each user."
"How does Next.js determine which components will be rendered dynamically?"
"If you use dynamic functions such as cookies() and headers(), or pass the cache: 'no-store' option to fetch, that component is automatically rendered dynamically. If it is inside a Suspense boundary, only that part is filled in later by streaming, and the parts outside it are pre-rendered statically."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Experimental feature: PPR is an experimental feature introduced in Next.js 14. Verify its stability before using it in production, and review the changes carefully when upgrading versions.
Suspense boundary: Dynamic components must be wrapped in Suspense for PPR to work properly. If you use a dynamic function without Suspense, the entire page switches to dynamic rendering and you lose the benefits of PPR.
Caching strategy: Static parts are cached on a CDN, so if changes are needed after the build, a redeployment is required. Separate frequently changing content into dynamic components or use it in combination with ISR.