Skip to content
RenderingChapter 13 / 34Intermediate5 min read

Streaming & Suspense

Next.js streaming suspense: stream a page in parts when data is slow, with Suspense boundaries, loading.tsx and parallel data fetching.

On this page

1. What are streaming and Suspense?

Suspense is a React component that says "show this fallback until the component inside is ready". Next.js watches these boundaries on the server and streams the HTML in chunks.

2. Why does it matter?

If one part of a page takes 3 seconds, then without streaming the whole page stays blank for 3 seconds.

Without streamingWith streaming
Blank screen until the slowest query finishesHeader and layout show immediately
One slow widget blocks the whole pageEach widget arrives when it is ready
The user thinks the site is frozenA skeleton shows progress
Higher Time to First ByteThe first byte arrives sooner

3. Where is it used?

PageWhat to stream
DashboardEach chart and stats card in its own boundary
Product pageReviews and recommendations later
Blog postThe comments section later
Search resultsThe results list with a skeleton
Cache Components pageEvery dynamic (request time) part

4. How does it work?

A streamed response
Request arrives
Layout and static parts render
Fallbacks are placed at the Suspense boundaries
The first HTML chunk goes to the browser (the user sees something)
Data for the slow component arrives
Its HTML is streamed in the same response
React replaces the fallback with the real UI

There are two ways to stream:

WayScope
loading.tsxThe whole page segment in one boundary
<Suspense>You choose the small parts yourself

loading.tsx actually wraps the page in Suspense for you. If you want more control, add Suspense yourself.

5. Code example

A dashboard whose widgets stream separately

tsx
import { Suspense } from "react";

async function Revenue() {
  const res = await fetch("https://api.example.com/revenue");
  const data = await res.json();
  return <p>Revenue: {data.total}</p>;
}

async function LatestOrders() {
  const res = await fetch("https://api.example.com/orders?limit=5");
  const orders: { id: string; amount: number }[] = await res.json();
  return (
    <ul>
      {orders.map((order) => (
        <li key={order.id}>{order.amount}</li>
      ))}
    </ul>
  );
}

export default function DashboardPage() {
  return (
    <main>
      <h1>Dashboard</h1>
      <Suspense fallback={<p>Loading revenue...</p>}>
        <Revenue />
      </Suspense>
      <Suspense fallback={<p>Loading orders...</p>}>
        <LatestOrders />
      </Suspense>
    </main>
  );
}

Parallel fetching to avoid a waterfall

tsx
async function getUser(id: string) {
  return fetch(`https://api.example.com/users/${id}`).then((r) => r.json());
}

async function getPosts(id: string) {
  return fetch(`https://api.example.com/users/${id}/posts`).then((r) => r.json());
}

export default async function ProfilePage({ params }: PageProps<"/users/[id]">) {
  const { id } = await params;
  const [user, posts] = await Promise.all([getUser(id), getPosts(id)]);
  return (
    <h1>
      {user.name} has {posts.length} posts
    </h1>
  );
}

How does the code work?

PartMeaning
async function RevenueAn async Server Component that fetches its own data
<Suspense fallback=...>Shows the fallback until the data arrives, then streams the real UI
Two separate boundariesRevenue and orders do not wait for each other
<h1>Dashboard</h1>Outside any boundary, so it shows immediately
Promise.allStarts both requests together, no waterfall

Interview tip

"Does streaming hurt SEO?" No. Streamed content is still HTML coming from the server in the same HTTP response, and crawlers like Google can read it.

6. Common mistakes

Mistake: Putting Suspense inside the async component

Why? The boundary must be above the component that suspends. Placing it inside does not work.

Better: Add Suspense in the parent and put the slow async component inside it.

Mistake: Awaiting one after another when the requests are independent

Why? Each request waits for the previous one, so the total time becomes the sum of all of them.

Better: Run independent requests together with Promise.all, or put them in separate Suspense boundaries.

Mistake: Wrapping the whole page in one boundary

Why? The slowest part blocks everything else too.

Better: Give every independent slow part its own Suspense boundary.

Mistake: Making the fallback a completely different size from the real UI

Why? The layout shifts when the content arrives and your CLS score gets worse.

Better: Keep the size and shape of the skeleton close to the real UI.

7. What to learn before and after

Final quick revision

PointDetail
StreamingHTML in parts, in a single response
Boundary<Suspense fallback=...>
Page levelloading.tsx
BenefitFaster first paint, independent widgets
Avoiding waterfallsPromise.all or separate boundaries
Cache ComponentsRequest time data must be inside Suspense