What is streaming in Next.js, and how does it improve the user experience?
Short answer
Streaming lets Next.js send parts of a page to the browser as soon as they are ready, instead of waiting for every piece of data on the page to finish loading first.
Advertisement
AModel answer
Streaming lets Next.js send parts of a page to the browser as soon as they are ready, instead of waiting for every piece of data on the page to finish loading first. This means fast parts of a page, like the header, can appear immediately, while slower parts load in and appear a moment later.
// app/page.js
import { Suspense } from 'react';
export default function Page() {
return (
<div>
<Header />
<Suspense fallback={<p>Loading comments...</p>}>
<Comments />
</Suspense>
</div>
);
}Real-world example
A news article page shows the article text immediately while a slower loading comments section streams in a moment later, so readers are not stuck waiting for the entire page before seeing anything.
Likely follow-ups
- What happens if a streamed component's data fetch fails?
- Can multiple Suspense boundaries be used on the same page?
Related topics