Hard15 minNext.js Fundamentals
UpdatedAug 3, 2026
Edit

Next.js Streaming & Suspense

CONCEPTS:Next.js Streaming and Suspense

Question Variations

  • "How does streaming improve the performance of a Next.js application?"
  • "What is the difference between `loading.js` and manual `<Suspense>` boundaries?"
  • "Does streaming affect SEO?"
  • "How do you handle a page where one component fetches data significantly slower than others?"

Why This Is Asked

Streaming is a core feature of the App Router that directly impacts Core Web Vitals and user perception of speed. Interviewers want to know if you can architect a page that stays responsive even when backend services are slow.

Key Concepts

  • Time to First Byte (TTFB) vs Largest Contentful Paint (LCP): How streaming affects these metrics.
  • loading.js: The convention-based approach to loading states.
  • Granular Suspense: Using <Suspense> to wrap specific slow-loading components.
  • SEO: Understanding that Next.js waits for the first chunk (including metadata) to be generated before sending anything to search engines.

Question Variations

  • “How does streaming improve the performance of a Next.js application?”
  • “What is the difference between loading.js and manual <Suspense> boundaries?”
  • “Does streaming affect SEO?”
  • “How do you handle a page where one component fetches data significantly slower than others?”

Answers by Technology

+ Add Variant
Next.jsImprove this answer ✏️

Expected Answer

Streaming works by breaking the page’s HTML into chunks. The server sends the “shell” (layouts, static content) immediately, and then streams the rest as data becomes available.

Key Techniques:

  1. loading.js: By creating a loading.js file in a route folder, Next.js automatically wraps the page.js (and any nested children) in a React Suspense boundary. It displays the loading UI until the page is ready.
  2. Manual Suspense: For more control, you can wrap individual components in <Suspense fallback={<Skeleton />}>. This is useful when you have multiple data-heavy components and don’t want the slowest one to delay the entire page.

SEO Note: Streaming is SEO-friendly. Next.js will wait for data fetching in Server Components to complete before finishing the stream. Search engines see the final rendered content, but users see the layout faster.

Why It Matters

In a traditional SSR model, the user sees nothing until all data for the page is fetched. If one microservice takes 2 seconds, the whole page is blank for 2 seconds. Streaming allows the user to start interacting with the parts of the page that are ready.

Example Code

Granular Suspense

TypeScript

import { Suspense } from 'react';
import { FastComponent, SlowComponent } from './components';

export default function Page() {
  return (
    <section>
      <h1>My Dashboard</h1>
      <FastComponent />
      <Suspense fallback={<p>Loading stats...</p>}>
        <SlowComponent />
      </Suspense>
    </section>
  );
}

JavaScript

import { Suspense } from 'react';
import { FastComponent, SlowComponent } from './components';

export default function Page() {
  return (
    <section>
      <h1>My Dashboard</h1>
      <FastComponent />
      <Suspense fallback={<p>Loading stats...</p>}>
        <SlowComponent />
      </Suspense>
    </section>
  );
}

Common Mistakes

  • Not using Skeletons: A simple “Loading…” text can be jarring. Skeletons provide a better visual cue of what the content will look like.
  • Over-nesting Suspense: Too many loading spinners can make the UI feel chaotic. It’s often better to group related components into a single boundary.
  • Forgetting that layouts aren’t wrapped by loading.js: The loading.js only wraps the page.js and nested segments. The layout itself is sent immediately.

Follow-up Questions

  • What happens if an error occurs during streaming? (Answer: Next.js will try to render the closest error.js boundary).
  • Can you stream on the client side? (Answer: Suspense works on the client too, but “Streaming” in Next.js specifically refers to the server-to-client transfer of HTML).

References