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:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
Use this file to discover all available pages before exploring further.
dynamic()fromnext/dynamic— the primary API for lazy loading in the App Router.React.lazy()withSuspense— 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, usessr: false. This is useful for components that depend on browser APIs:
Named exports
To lazy load a named export from a module, return it from thePromise returned by the dynamic import:
Lazy loading libraries
Third-party libraries can also be loaded on demand usingimport() 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
A function that returns a
Promise resolving to the component module. Usually an import() call.A component to render while the dynamic component is loading.
Whether to server-side render the component. Set to
false to skip SSR for browser-only components.