Routing - Loading UI and Streaming - Next - Js
Routing - Loading UI and Streaming - Next - Js
js
Menu
. With this convention, you can show an instant loading state from the server while the
content of a route segment loads. The new content is automatically swapped in once
rendering is complete.
An instant loading state is fallback UI that is shown immediately upon navigation. You can
pre-render loading indicators such as skeletons and spinners, or a small but meaningful
part of future screens such as a cover photo, title, etc. This helps users understand the app
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 1/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
app/dashboard/loading.tsx TypeScript
In the same folder, loading.js will be nested inside layout.js . It will automatically wrap
Good to know:
- Navigation is interruptible, meaning changing routes does not need to wait for the content of the
route to fully load before navigating to another route.
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 2/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
Recommendation: Use the loading.js convention for route segments (layouts and pages) as
Next.js optimizes this functionality.
In addition to loading.js , you can also manually create Suspense Boundaries for your
own UI components. The App Router supports streaming with Suspense for both Node.js
What is Streaming?
To learn how Streaming works in React and Next.js, it's helpful to understand Server-Side
With SSR, there's a series of steps that need to be completed before a user can see and
3. The HTML, CSS, and JavaScript for the page are sent to the client.
4. A non-interactive user interface is shown using the generated HTML, and CSS.
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 3/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
These steps are sequential and blocking, meaning the server can only render the HTML for
a page once all the data has been fetched. And, on the client, React can only hydrate the UI
once the code for all components in the page has been downloaded.
SSR with React and Next.js helps improve the perceived loading performance by showing a
However, it can still be slow as all data fetching on server needs to be completed before the
Streaming allows you to break down the page's HTML into smaller chunks and
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 4/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
This enables parts of the page to be displayed sooner, without waiting for all the data to
Streaming works well with React's component model because each component can be
considered a chunk. Components that have higher priority (e.g. product information) or that
don't rely on data can be sent first (e.g. layout), and React can start hydration earlier.
Components that have lower priority (e.g. reviews, related products) can be sent in the same
Streaming is particularly beneficial when you want to prevent long data requests from
blocking the page from rendering as it can reduce the Time To First Byte (TTFB) and First
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 5/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
Contentful Paint (FCP) . It also helps improve Time to Interactive (TTI) , especially on
slower devices.
Example
fetch data), showing fallback UI (e.g. skeleton, spinner) while it's happening, and then
app/dashboard/page.tsx TypeScript
1. Streaming Server Rendering - Progressively rendering HTML from the server to the
client.
For more Suspense examples and use cases, please see the React Documentation .
SEO
- Next.js will wait for data fetching inside generateMetadata to complete before
streaming UI to the client. This guarantees the first part of a streamed response
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 6/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
- Since streaming is server-rendered, it does not impact SEO. You can use the Rich
Results Test tool from Google to see how your page appears to Google's web crawlers
Status Codes
When streaming, a 200 status code will be returned to signal that the request was
successful.
The server can still communicate errors or issues to the client within the streamed content
itself, for example, when using redirect or notFound . Since the response headers have
already been sent to the client, the status code of the response cannot be updated. This
Previous Next
Blog Releases X
Analytics Telemetry
DX Platform
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 7/8
28/2/24, 11:31 Routing: Loading UI and Streaming | Next.js
you@domain.com Subscribe
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming 8/8