Skip to main content
Lazy loading in Next.js helps reduce the initial JavaScript bundle by deferring the load of components and libraries until they’re needed. There are two main approaches:
  1. dynamic() from next/dynamic — the primary API for lazy loading in the App Router.
  2. React.lazy() with Suspense — works in Client Components.

dynamic()

next/dynamic is a combination of React.lazy() and Suspense. It works in both Server and Client Components.

Basic usage

Loading UI

Show a fallback while the component loads:

Disabling SSR

To prevent a component from rendering on the server, use ssr: false. This is useful for components that depend on browser APIs:
Using ssr: false prevents any server-rendered HTML for that component. Use only when necessary, such as for components that access window or other browser-only globals.

Named exports

To lazy load a named export from a module, return it from the Promise returned by the dynamic import:

Lazy loading libraries

Third-party libraries can also be loaded on demand using import() inside an event handler:
app/page.tsx

React.lazy() with Suspense

Inside Client Components, you can use React.lazy() and Suspense directly:
app/page.tsx
dynamic() from next/dynamic supports additional options like ssr: false that React.lazy() does not. Prefer dynamic() for full Next.js feature support.

dynamic() options reference

function
required
A function that returns a Promise resolving to the component module. Usually an import() call.
function
A component to render while the dynamic component is loading.
boolean
default:"true"
Whether to server-side render the component. Set to false to skip SSR for browser-only components.