metadata
dict | url
stringlengths 19
103
| markdown
stringlengths 199
68.6k
|
---|---|---|
{
"contentLength": null,
"etag": "W/\"7a75ffd1bb3b60f5b7cbd4e58aca12e7\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/deploying/production-checklist | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [
Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Automatic optimizations](#automatic-optimizations)
* [During development](#during-development)
* [Routing and rendering](#routing-and-rendering)
* [Data fetching and caching](#data-fetching-and-caching)
* [UI and accessibility](#ui-and-accessibility)
* [Security](#security)
* [Metadata and SEO](#metadata-and-seo)
* [Type safety](#type-safety)
* [Before going to production](#before-going-to-production)
* [Core Web Vitals](#core-web-vitals)
* [Analyzing bundles](#analyzing-bundles)
* [After deployment](#after-deployment)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/09-deploying/01-production-checklist.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Deploying](/docs/pages/building-your-application/deploying)Production Checklist
Production Checklist
====================
Before taking your Next.js application to production, there are some optimizations and patterns you should consider implementing for the best user experience, performance, and security.
This page provides best practices that you can use as a reference when [building your application](#during-development), [before going to production](#before-going-to-production), and [after deployment](#after-deployment) - as well as the [automatic Next.js optimizations](#automatic-optimizations) you should be aware of.
[Automatic optimizations](#automatic-optimizations)
---------------------------------------------------
These Next.js optimizations are enabled by default and require no configuration:
* **[Code-splitting](/docs/pages/building-your-application/routing/pages-and-layouts):** Next.js automatically code-splits your application code by pages. This means only the code needed for the current page is loaded on navigation. You may also consider [lazy loading](/docs/pages/building-your-application/optimizing/lazy-loading) third-party libraries, where appropriate.
* **[Prefetching](/docs/pages/api-reference/components/link#prefetch):** When a link to a new route enters the user's viewport, Next.js prefetches the route in background. This makes navigation to new routes almost instant. You can opt out of prefetching, where appropriate.
* **[Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization):** Next.js automatically determines that a page is static (can be pre-rendered) if it has no blocking data requirements. Optimized pages can be cached, and served to the end-user from multiple CDN locations. You may opt into [Server-side Rendering](/docs/pages/building-your-application/data-fetching/get-server-side-props), where appropriate.
These defaults aim to improve your application's performance, and reduce the cost and amount of data transferred on each network request.
[During development](#during-development)
-----------------------------------------
While building your application, we recommend using the following features to ensure the best performance and user experience:
### [Routing and rendering](#routing-and-rendering)
* **[`<Link>` component](/docs/pages/building-your-application/routing/linking-and-navigating):** Use the `<Link>` component for client-side navigation and prefetching.
* **[Custom Errors](/docs/pages/building-your-application/routing/custom-error):** Gracefully handle [500](/docs/pages/building-your-application/routing/custom-error#500-page) and [404 errors](/docs/pages/building-your-application/routing/custom-error#404-page)
### [Data fetching and caching](#data-fetching-and-caching)
* **[API Routes](/docs/pages/building-your-application/routing/api-routes):** Use Route Handlers to access your backend resources, and prevent sensitive secrets from being exposed to the client.
* **[Data Caching](/docs/pages/building-your-application/data-fetching/get-static-props):** Verify whether your data requests are being cached or not, and opt into caching, where appropriate. Ensure requests that don't use `getStaticProps` are cached where appropriate.
* **[Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration):** Use Incremental Static Regeneration to update static pages after they've been built, without rebuilding your entire site.
* **[Static Images](/docs/pages/building-your-application/optimizing/static-assets):** Use the `public` directory to automatically cache your application's static assets, e.g. images.
### [UI and accessibility](#ui-and-accessibility)
* **[Font Module](/docs/app/building-your-application/optimizing/fonts):** Optimize fonts by using the Font Module, which automatically hosts your font files with other static assets, removes external network requests, and reduces [layout shift](https://web.dev/articles/cls).
* **[`<Image>` Component](/docs/app/building-your-application/optimizing/images):** Optimize images by using the Image Component, which automatically optimizes images, prevents layout shift, and serves them in modern formats like WebP or AVIF.
* **[`<Script>` Component](/docs/app/building-your-application/optimizing/scripts):** Optimize third-party scripts by using the Script Component, which automatically defers scripts and prevents them from blocking the main thread.
* **[ESLint](/docs/architecture/accessibility#linting):** Use the built-in `eslint-plugin-jsx-a11y` plugin to catch accessibility issues early.
### [Security](#security)
* **[Environment Variables](/docs/app/building-your-application/configuring/environment-variables):** Ensure your `.env.*` files are added to `.gitignore` and only public variables are prefixed with `NEXT_PUBLIC_`.
* **[Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy):** Consider adding a Content Security Policy to protect your application against various security threats such as cross-site scripting, clickjacking, and other code injection attacks.
### [Metadata and SEO](#metadata-and-seo)
* **[`<Head>` Component](/docs/pages/api-reference/components/head):** Use the `next/head` component to add page titles, descriptions, and more.
### [Type safety](#type-safety)
* **TypeScript and [TS Plugin](/docs/app/building-your-application/configuring/typescript):** Use TypeScript and the TypeScript plugin for better type-safety, and to help you catch errors early.
[Before going to production](#before-going-to-production)
---------------------------------------------------------
Before going to production, you can run `next build` to build your application locally and catch any build errors, then run `next start` to measure the performance of your application in a production-like environment.
### [Core Web Vitals](#core-web-vitals)
* **[Lighthouse](https://developers.google.com/web/tools/lighthouse):** Run lighthouse in incognito to gain a better understanding of how your users will experience your site, and to identify areas for improvement. This is a simulated test and should be paired with looking at field data (such as Core Web Vitals).
### [Analyzing bundles](#analyzing-bundles)
Use the [`@next/bundle-analyzer` plugin](/docs/app/building-your-application/optimizing/bundle-analyzer) to analyze the size of your JavaScript bundles and identify large modules and dependencies that might be impacting your application's performance.
Additionally, the following tools can you understand the impact of adding new dependencies to your application:
* [Import Cost](https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost)
* [Package Phobia](https://packagephobia.com/)
* [Bundle Phobia](https://bundlephobia.com/)
* [bundlejs](https://bundlejs.com/)
[After deployment](#after-deployment)
-------------------------------------
Depending on where you deploy your application, you might have access to additional tools and integrations to help you monitor and improve your application's performance.
For Vercel deployments, we recommend the following:
* **[Analytics](https://vercel.com/analytics?utm_source=next-site&utm_campaign=nextjs-docs&utm_medium=docs):** A built-in analytics dashboard to help you understand your application's traffic, including the number of unique visitors, page views, and more.
* **[Speed Insights](https://vercel.com/docs/speed-insights?utm_source=next-site&utm_campaign=nextjs-docs&utm_medium=docs):** Real-world performance insights based on visitor data, offering a practical view of how your website is performing in the field.
* **[Logging](https://vercel.com/docs/observability/runtime-logs?utm_source=next-site&utm_campaign=nextjs-docs&utm_medium=docs):** Runtime and Activity logs to help you debug issues and monitor your application in production. Alternatively, see the [integrations page](https://vercel.com/integrations?utm_source=next-site&utm_campaign=nextjs-docs&utm_medium=docs) for a list of third-party tools and services.
> **Good to know:**
>
> To get a comprehensive understanding of the best practices for production deployments on Vercel, including detailed strategies for improving website performance, refer to the [Vercel Production Checklist](https://vercel.com/docs/production-checklist?utm_source=next-site&utm_campaign=nextjs-docs&utm_medium=docs).
Following these recommendations will help you build a faster, more reliable, and secure application for your users.
[Previous
Deploying
](/docs/pages/building-your-application/deploying)
[Next
Static Exports
](/docs/pages/building-your-application/deploying/static-exports)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"67fbcbd6849b7550b31b7e3454a75301\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/configuring/content-security-policy | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [
Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Nonces](#nonces)
* [Why use a nonce?](#why-use-a-nonce)
* [Adding a nonce with Middleware](#adding-a-nonce-with-middleware)
* [Reading the nonce](#reading-the-nonce)
* [Without Nonces](#without-nonces)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/06-configuring/15-content-security-policy.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Configuring](/docs/pages/building-your-application/configuring)Content Security Policy
Content Security Policy
=======================
[Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP) is important to guard your Next.js application against various security threats such as cross-site scripting (XSS), clickjacking, and other code injection attacks.
By using CSP, developers can specify which origins are permissible for content sources, scripts, stylesheets, images, fonts, objects, media (audio, video), iframes, and more.
Examples
* [Strict CSP](https://github.com/vercel/next.js/tree/canary/examples/with-strict-csp)
[Nonces](#nonces)
-----------------
A [nonce](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/nonce) is a unique, random string of characters created for a one-time use. It is used in conjunction with CSP to selectively allow certain inline scripts or styles to execute, bypassing strict CSP directives.
### [Why use a nonce?](#why-use-a-nonce)
Even though CSPs are designed to block malicious scripts, there are legitimate scenarios where inline scripts are necessary. In such cases, nonces offer a way to allow these scripts to execute if they have the correct nonce.
### [Adding a nonce with Middleware](#adding-a-nonce-with-middleware)
[Middleware](/docs/app/building-your-application/routing/middleware) enables you to add headers and generate nonces before the page renders.
Every time a page is viewed, a fresh nonce should be generated. This means that you **must use dynamic rendering to add nonces**.
For example:
middleware.ts
TypeScript
JavaScriptTypeScript
import { NextRequest, NextResponse } from 'next/server'
export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString('base64')
const cspHeader = `
default-src 'self';
script-src 'self' 'nonce-${nonce}' 'strict-dynamic';
style-src 'self' 'nonce-${nonce}';
img-src 'self' blob: data:;
font-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
`
// Replace newline characters and spaces
const contentSecurityPolicyHeaderValue = cspHeader
.replace(/\s{2,}/g, ' ')
.trim()
const requestHeaders = new Headers(request.headers)
requestHeaders.set('x-nonce', nonce)
requestHeaders.set(
'Content-Security-Policy',
contentSecurityPolicyHeaderValue
)
const response = NextResponse.next({
request: {
headers: requestHeaders,
},
})
response.headers.set(
'Content-Security-Policy',
contentSecurityPolicyHeaderValue
)
return response
}
By default, Middleware runs on all requests. You can filter Middleware to run on specific paths using a [`matcher`](/docs/app/building-your-application/routing/middleware#matcher).
We recommend ignoring matching prefetches (from `next/link`) and static assets that don't need the CSP header.
middleware.ts
TypeScript
JavaScriptTypeScript
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
{
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
missing: [
{ type: 'header', key: 'next-router-prefetch' },
{ type: 'header', key: 'purpose', value: 'prefetch' },
],
},
],
}
### [Reading the nonce](#reading-the-nonce)
You can now read the nonce from a [Server Component](/docs/app/building-your-application/rendering/server-components) using [`headers`](/docs/app/api-reference/functions/headers):
app/page.tsx
TypeScript
JavaScriptTypeScript
import { headers } from 'next/headers'
import Script from 'next/script'
export default function Page() {
const nonce = headers().get('x-nonce')
return (
<Script
src="https://www.googletagmanager.com/gtag/js"
strategy="afterInteractive"
nonce={nonce}
/>
)
}
[Without Nonces](#without-nonces)
---------------------------------
For applications that do not require nonces, you can set the CSP header directly in your [`next.config.js`](/docs/app/api-reference/next-config-js) file:
next.config.js
const cspHeader = `
default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' blob: data:;
font-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
`
module.exports = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, ''),
},
],
},
]
},
}
[Version History](#version-history)
-----------------------------------
We recommend using `v13.4.20+` of Next.js to properly handle and apply nonces.
[Previous
Preview Mode
](/docs/pages/building-your-application/configuring/preview-mode)
[Next
Testing
](/docs/pages/building-your-application/testing)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"9057d729dac18284e9076c72f8a8d6fc\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/deploying | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Production Builds](#production-builds)
* [Managed Next.js with Vercel](#managed-nextjs-with-vercel)
* [Self-Hosting](#self-hosting)
* [Node.js Server](#nodejs-server)
* [Docker Image](#docker-image)
* [Static HTML Export](#static-html-export)
* [Features](#features)
* [Image Optimization](#image-optimization)
* [Middleware](#middleware)
* [Environment Variables](#environment-variables)
* [Caching and ISR](#caching-and-isr)
* [Automatic Caching](#automatic-caching)
* [Static Assets](#static-assets)
* [Configuring Caching](#configuring-caching)
* [Build Cache](#build-cache)
* [Version Skew](#version-skew)
* [Manual Graceful Shutdowns](#manual-graceful-shutdowns)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/09-deploying/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[Building Your Application](/docs/pages/building-your-application)Deploying
Deploying
=========
Congratulations, it's time to ship to production.
You can deploy [managed Next.js with Vercel](#managed-nextjs-with-vercel), or self-host on a Node.js server, Docker image, or even static HTML files. When deploying using `next start`, all Next.js features are supported.
[Production Builds](#production-builds)
---------------------------------------
Running `next build` generates an optimized version of your application for production. HTML, CSS, and JavaScript files are created based on your pages. JavaScript is **compiled** and browser bundles are **minified** using the [Next.js Compiler](/docs/architecture/nextjs-compiler) to help achieve the best performance and support [all modern browsers](/docs/architecture/supported-browsers).
Next.js produces a standard deployment output used by managed and self-hosted Next.js. This ensures all features are supported across both methods of deployment. In the next major version, we will be transforming this output into our [Build Output API specification](https://vercel.com/docs/build-output-api/v3?utm_source=next-site&utm_medium=docs&utm_campaign=next-website).
[Managed Next.js with Vercel](#managed-nextjs-with-vercel)
----------------------------------------------------------
[Vercel](https://vercel.com/docs/frameworks/nextjs?utm_source=next-site&utm_medium=docs&utm_campaign=next-website), the creators and maintainers of Next.js, provide managed infrastructure and a developer experience platform for your Next.js applications.
Deploying to Vercel is zero-configuration and provides additional enhancements for scalability, availability, and performance globally. However, all Next.js features are still supported when self-hosted.
Learn more about [Next.js on Vercel](https://vercel.com/docs/frameworks/nextjs?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) or [deploy a template for free](https://vercel.com/templates/next.js?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) to try it out.
[Self-Hosting](#self-hosting)
-----------------------------
You can self-host Next.js in three different ways:
* [A Node.js server](#nodejs-server)
* [A Docker container](#docker-image)
* [A static export](#static-html-export)
### [Node.js Server](#nodejs-server)
Next.js can be deployed to any hosting provider that supports Node.js. Ensure your `package.json` has the `"build"` and `"start"` scripts:
package.json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
Then, run `npm run build` to build your application. Finally, run `npm run start` to start the Node.js server. This server supports all Next.js features.
### [Docker Image](#docker-image)
Next.js can be deployed to any hosting provider that supports [Docker](https://www.docker.com/) containers. You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or when running inside a container in any cloud provider.
1. [Install Docker](https://docs.docker.com/get-docker/) on your machine
2. [Clone our example](https://github.com/vercel/next.js/tree/canary/examples/with-docker) (or the [multi-environment example](https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env))
3. Build your container: `docker build -t nextjs-docker .`
4. Run your container: `docker run -p 3000:3000 nextjs-docker`
Next.js through Docker supports all Next.js features.
### [Static HTML Export](#static-html-export)
Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.
Since Next.js supports this [static export](/docs/app/building-your-application/deploying/static-exports), it can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets. This includes tools like AWS S3, Nginx, or Apache.
Running as a [static export](/docs/app/building-your-application/deploying/static-exports) does not support Next.js features that require a server. [Learn more](/docs/app/building-your-application/deploying/static-exports#unsupported-features).
> **Good to know:**
>
> * [Server Components](/docs/app/building-your-application/rendering/server-components) are supported with static exports.
[Features](#features)
---------------------
### [Image Optimization](#image-optimization)
[Image Optimization](/docs/app/building-your-application/optimizing/images) through `next/image` works self-hosted with zero configuration when deploying using `next start`. If you would prefer to have a separate service to optimize images, you can [configure an image loader](/docs/app/building-your-application/optimizing/images#loaders).
Image Optimization can be used with a [static export](/docs/app/building-your-application/deploying/static-exports#image-optimization) by defining a custom image loader in `next.config.js`. Note that images are optimized at runtime, not during the build.
> **Good to know:**
>
> * When self-hosting, consider installing `sharp` for more performant [Image Optimization](/docs/pages/building-your-application/optimizing/images) in your production environment by running `npm install sharp` in your project directory. On Linux platforms, `sharp` may require [additional configuration](https://sharp.pixelplumbing.com/install#linux-memory-allocator) to prevent excessive memory usage.
> * Learn more about the [caching behavior of optimized images](/docs/app/api-reference/components/image#caching-behavior) and how to configure the TTL.
> * You can also [disable Image Optimization](/docs/app/api-reference/components/image#unoptimized) and still retain other benefits of using `next/image` if you prefer. For example, if you are optimizing images yourself separately.
### [Middleware](#middleware)
[Middleware](/docs/app/building-your-application/routing/middleware) works self-hosted with zero configuration when deploying using `next start`. Since it requires access to the incoming request, it is not supported when using a [static export](/docs/app/building-your-application/deploying/static-exports).
Middleware uses a [runtime](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes) that is a subset of all available Node.js APIs to help ensure low latency, since it may run in front of every route or asset in your application. This runtime does not require running “at the edge” and works in a single-region server. Additional configuration and infrastructure are required to run Middleware in multiple regions.
If you are looking to add logic (or use an external package) that requires all Node.js APIs, you might be able to move this logic to a [layout](/docs/app/building-your-application/routing/pages-and-layouts#layouts) as a [Server Component](/docs/app/building-your-application/rendering/server-components). For example, checking [headers](/docs/app/api-reference/functions/headers) and [redirecting](/docs/app/api-reference/functions/redirect). You can also use headers, cookies, or query parameters to [redirect](/docs/app/api-reference/next-config-js/redirects#header-cookie-and-query-matching) or [rewrite](/docs/app/api-reference/next-config-js/rewrites#header-cookie-and-query-matching) through `next.config.js`. If that does not work, you can also use a [custom server](/docs/pages/building-your-application/configuring/custom-server).
### [Environment Variables](#environment-variables)
Next.js can support both build time and runtime environment variables.
**By default, environment variables are only available on the server**. To expose an environment variable to the browser, it must be prefixed with `NEXT_PUBLIC_`. However, these public environment variables will be inlined into the JavaScript bundle during `next build`.
To read runtime environment variables, we recommend using `getServerSideProps` or [incrementally adopting the App Router](/docs/app/building-your-application/upgrading/app-router-migration). With the App Router, we can safely read environment variables on the server during dynamic rendering. This allows you to use a singular Docker image that can be promoted through multiple environments with different values.
import { unstable_noStore as noStore } from 'next/cache';
export default function Component() {
noStore();
// cookies(), headers(), and other dynamic functions
// will also opt into dynamic rendering, making
// this env variable is evaluated at runtime
const value = process.env.MY_VALUE
...
}
> **Good to know:**
>
> * You can run code on server startup using the [`register` function](/docs/app/building-your-application/optimizing/instrumentation).
> * We do not recommend using the [runtimeConfig](/docs/pages/api-reference/next-config-js/runtime-configuration) option, as this does not work with the standalone output mode. Instead, we recommend [incrementally adopting](/docs/app/building-your-application/upgrading/app-router-migration) the App Router.
### [Caching and ISR](#caching-and-isr)
Next.js can cache responses, generated static pages, build outputs, and other static assets like images, fonts, and scripts.
Caching and revalidating pages (using Incremental Static Regeneration (ISR) or newer functions in the App Router) use the **same shared cache**. By default, this cache is stored to the filesystem (on disk) on your Next.js server. **This works automatically when self-hosting** using both the Pages and App Router.
You can configure the Next.js cache location if you want to persist cached pages and data to durable storage, or share the cache across multiple containers or instances of your Next.js application.
#### [Automatic Caching](#automatic-caching)
* Next.js sets the `Cache-Control` header of `public, max-age=31536000, immutable` to truly immutable assets. It cannot be overridden. These immutable files contain a SHA-hash in the file name, so they can be safely cached indefinitely. For example, [Static Image Imports](/docs/app/building-your-application/optimizing/images#local-images). You can [configure the TTL](/docs/app/api-reference/components/image#caching-behavior) for images.
* Incremental Static Regeneration (ISR) sets the `Cache-Control` header of `s-maxage: <revalidate in getStaticProps>, stale-while-revalidate`. This revalidation time is defined in your [`getStaticProps` function](/docs/pages/building-your-application/data-fetching/get-static-props) in seconds. If you set `revalidate: false`, it will default to a one-year cache duration.
* Dynamically rendered pages set a `Cache-Control` header of `private, no-cache, no-store, max-age=0, must-revalidate` to prevent user-specific data from being cached. This applies to both the App Router and Pages Router. This also includes [Draft Mode](/docs/app/building-your-application/configuring/draft-mode).
#### [Static Assets](#static-assets)
If you want to host static assets on a different domain or CDN, you can use the `assetPrefix` [configuration](/docs/app/api-reference/next-config-js/assetPrefix) in `next.config.js`. Next.js will use this asset prefix when retrieving JavaScript or CSS files. Separating your assets to a different domain does come with the downside of extra time spent on DNS and TLS resolution.
[Learn more about `assetPrefix`](/docs/app/api-reference/next-config-js/assetPrefix).
#### [Configuring Caching](#configuring-caching)
By default, generated cache assets will be stored in memory (defaults to 50mb) and on disk. If you are hosting Next.js using a container orchestration platform like Kubernetes, each pod will have a copy of the cache. To prevent stale data from being shown since the cache is not shared between pods by default, you can configure the Next.js cache to provide a cache handler and disable in-memory caching.
To configure the ISR/Data Cache location when self-hosting, you can configure a custom handler in your `next.config.js` file:
next.config.js
module.exports = {
cacheHandler: require.resolve('./cache-handler.js'),
cacheMaxMemorySize: 0, // disable default in-memory caching
}
Then, create `cache-handler.js` in the root of your project, for example:
cache-handler.js
const cache = new Map()
module.exports = class CacheHandler {
constructor(options) {
this.options = options
}
async get(key) {
// This could be stored anywhere, like durable storage
return cache.get(key)
}
async set(key, data, ctx) {
// This could be stored anywhere, like durable storage
cache.set(key, {
value: data,
lastModified: Date.now(),
tags: ctx.tags,
})
}
async revalidateTag(tag) {
// Iterate over all entries in the cache
for (let [key, value] of cache) {
// If the value's tags include the specified tag, delete this entry
if (value.tags.includes(tag)) {
cache.delete(key)
}
}
}
}
Using a custom cache handler will allow you to ensure consistency across all pods hosting your Next.js application. For instance, you can save the cached values anywhere, like [Redis](https://github.com/vercel/next.js/tree/canary/examples/cache-handler-redis) or AWS S3.
> **Good to know:**
>
> * `revalidatePath` is a convenience layer on top of cache tags. Calling `revalidatePath` will call the `revalidateTag` function with a special default tag for the provided page.
### [Build Cache](#build-cache)
Next.js generates an ID during `next build` to identify which version of your application is being served. The same build should be used and boot up multiple containers.
If you are rebuilding for each stage of your environment, you will need to generate a consistent build ID to use between containers. Use the `generateBuildId` command in `next.config.js`:
next.config.js
module.exports = {
generateBuildId: async () => {
// This could be anything, using the latest git hash
return process.env.GIT_HASH
},
}
### [Version Skew](#version-skew)
Next.js will automatically mitigate most instances of [version skew](https://www.industrialempathy.com/posts/version-skew/) and automatically reload the application to retrieve new assets when detected. For example, if there is a mismatch in the `deploymentId`, transitions between pages will perform a hard navigation versus using a prefetched value.
When the application is reloaded, there may be a loss of application state if it's not designed to persist between page navigations. For example, using URL state or local storage would persist state after a page refresh. However, component state like `useState` would be lost in such navigations.
Vercel provides additional [skew protection](https://vercel.com/docs/deployments/skew-protection?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) for Next.js applications to ensure assets and functions from the previous version are still available to older clients, even after the new version is deployed.
You can manually configure the `deploymentId` property in your `next.config.js` file to ensure each request uses either `?dpl` query string or `x-deployment-id` header.
[Manual Graceful Shutdowns](#manual-graceful-shutdowns)
-------------------------------------------------------
When self-hosting, you might want to run code when the server shuts down on `SIGTERM` or `SIGINT` signals.
You can set the env variable `NEXT_MANUAL_SIG_HANDLE` to `true` and then register a handler for that signal inside your `_document.js` file. You will need to register the environment variable directly in the `package.json` script, and not in the `.env` file.
> **Good to know**: Manual signal handling is not available in `next dev`.
package.json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "NEXT_MANUAL_SIG_HANDLE=true next start"
}
}
pages/\_document.js
if (process.env.NEXT_MANUAL_SIG_HANDLE) {
process.on('SIGTERM', () => {
console.log('Received SIGTERM: cleaning up')
process.exit(0)
})
process.on('SIGINT', () => {
console.log('Received SIGINT: cleaning up')
process.exit(0)
})
}
[
### Production Checklist
Recommendations to ensure the best performance and user experience before taking your Next.js application to production.
](/docs/pages/building-your-application/deploying/production-checklist)[
### Static Exports
Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.
](/docs/pages/building-your-application/deploying/static-exports)[
### Multi Zones
Learn how to use multi zones to deploy multiple Next.js apps as a single app.
](/docs/pages/building-your-application/deploying/multi-zones)[
### Continuous Integration (CI) Build Caching
Learn how to configure CI to cache Next.js builds
](/docs/pages/building-your-application/deploying/ci-build-caching)
[Previous
Authentication
](/docs/pages/building-your-application/authentication)
[Next
Production Checklist
](/docs/pages/building-your-application/deploying/production-checklist)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"8e64640c02616e71d2dd62cb4f335c47\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/codemods | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [
Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Usage](#usage)
* [Next.js Codemods](#nextjs-codemods)
* [14.0](#140)
* [Migrate ImageResponse imports](#migrate-imageresponse-imports)
* [next-og-import](#next-og-import)
* [Use viewport export](#use-viewport-export)
* [metadata-to-viewport-export](#metadata-to-viewport-export)
* [13.2](#132)
* [Use Built-in Font](#use-built-in-font)
* [built-in-next-font](#built-in-next-font)
* [13.0](#130)
* [Rename Next Image Imports](#rename-next-image-imports)
* [next-image-to-legacy-image](#next-image-to-legacy-image)
* [Migrate to the New Image Component](#migrate-to-the-new-image-component)
* [next-image-experimental](#next-image-experimental)
* [Remove <a> Tags From Link Components](#remove-a-tags-from-link-components)
* [new-link](#new-link)
* [11](#11)
* [Migrate from CRA](#migrate-from-cra)
* [cra-to-next](#cra-to-next)
* [10](#10)
* [Add React imports](#add-react-imports)
* [add-missing-react-import](#add-missing-react-import)
* [9](#9)
* [Transform Anonymous Components into Named Components](#transform-anonymous-components-into-named-components)
* [name-default-component](#name-default-component)
* [8](#8)
* [Transform AMP HOC into page config](#transform-amp-hoc-into-page-config)
* [withamp-to-config](#withamp-to-config)
* [6](#6)
* [Use withRouter](#use-withrouter)
* [url-to-withrouter](#url-to-withrouter)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/01-codemods.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Codemods
Codemods
========
Codemods are transformations that run on your codebase programmatically. This allows a large number of changes to be programmatically applied without having to manually go through every file.
Next.js provides Codemod transformations to help upgrade your Next.js codebase when an API is updated or deprecated.
[Usage](#usage)
---------------
In your terminal, navigate (`cd`) into your project's folder, then run:
Terminal
npx @next/codemod <transform> <path>
Replacing `<transform>` and `<path>` with appropriate values.
* `transform` - name of transform
* `path` - files or directory to transform
* `--dry` Do a dry-run, no code will be edited
* `--print` Prints the changed output for comparison
[Next.js Codemods](#nextjs-codemods)
------------------------------------
### [14.0](#140)
#### [Migrate `ImageResponse` imports](#migrate-imageresponse-imports)
##### [`next-og-import`](#next-og-import)
Terminal
npx @next/codemod@latest next-og-import .
This codemod moves transforms imports from `next/server` to `next/og` for usage of [Dynamic OG Image Generation](/docs/app/building-your-application/optimizing/metadata#dynamic-image-generation).
For example:
import { ImageResponse } from 'next/server'
Transforms into:
import { ImageResponse } from 'next/og'
#### [Use `viewport` export](#use-viewport-export)
##### [`metadata-to-viewport-export`](#metadata-to-viewport-export)
Terminal
npx @next/codemod@latest metadata-to-viewport-export .
This codemod migrates certain viewport metadata to `viewport` export.
For example:
export const metadata = {
title: 'My App',
themeColor: 'dark',
viewport: {
width: 1,
},
}
Transforms into:
export const metadata = {
title: 'My App',
}
export const viewport = {
width: 1,
themeColor: 'dark',
}
### [13.2](#132)
#### [Use Built-in Font](#use-built-in-font)
##### [`built-in-next-font`](#built-in-next-font)
Terminal
npx @next/codemod@latest built-in-next-font .
This codemod uninstalls the `@next/font` package and transforms `@next/font` imports into the built-in `next/font`.
For example:
import { Inter } from '@next/font/google'
Transforms into:
import { Inter } from 'next/font/google'
### [13.0](#130)
#### [Rename Next Image Imports](#rename-next-image-imports)
##### [`next-image-to-legacy-image`](#next-image-to-legacy-image)
Terminal
npx @next/codemod@latest next-image-to-legacy-image .
Safely renames `next/image` imports in existing Next.js 10, 11, or 12 applications to `next/legacy/image` in Next.js 13. Also renames `next/future/image` to `next/image`.
For example:
pages/index.js
import Image1 from 'next/image'
import Image2 from 'next/future/image'
export default function Home() {
return (
<div>
<Image1 src="/test.jpg" width="200" height="300" />
<Image2 src="/test.png" width="500" height="400" />
</div>
)
}
Transforms into:
pages/index.js
// 'next/image' becomes 'next/legacy/image'
import Image1 from 'next/legacy/image'
// 'next/future/image' becomes 'next/image'
import Image2 from 'next/image'
export default function Home() {
return (
<div>
<Image1 src="/test.jpg" width="200" height="300" />
<Image2 src="/test.png" width="500" height="400" />
</div>
)
}
#### [Migrate to the New Image Component](#migrate-to-the-new-image-component)
##### [`next-image-experimental`](#next-image-experimental)
Terminal
npx @next/codemod@latest next-image-experimental .
Dangerously migrates from `next/legacy/image` to the new `next/image` by adding inline styles and removing unused props.
* Removes `layout` prop and adds `style`.
* Removes `objectFit` prop and adds `style`.
* Removes `objectPosition` prop and adds `style`.
* Removes `lazyBoundary` prop.
* Removes `lazyRoot` prop.
#### [Remove `<a>` Tags From Link Components](#remove-a-tags-from-link-components)
##### [`new-link`](#new-link)
Terminal
npx @next/codemod@latest new-link .
Remove `<a>` tags inside [Link Components](/docs/pages/api-reference/components/link), or add a `legacyBehavior` prop to Links that cannot be auto-fixed.
For example:
<Link href="/about">
<a>About</a>
</Link>
// transforms into
<Link href="/about">
About
</Link>
<Link href="/about">
<a onClick={() => console.log('clicked')}>About</a>
</Link>
// transforms into
<Link href="/about" onClick={() => console.log('clicked')}>
About
</Link>
In cases where auto-fixing can't be applied, the `legacyBehavior` prop is added. This allows your app to keep functioning using the old behavior for that particular link.
const Component = () => <a>About</a>
<Link href="/about">
<Component />
</Link>
// becomes
<Link href="/about" legacyBehavior>
<Component />
</Link>
### [11](#11)
#### [Migrate from CRA](#migrate-from-cra)
##### [`cra-to-next`](#cra-to-next)
Terminal
npx @next/codemod cra-to-next
Migrates a Create React App project to Next.js; creating a Pages Router and necessary config to match behavior. Client-side only rendering is leveraged initially to prevent breaking compatibility due to `window` usage during SSR and can be enabled seamlessly to allow the gradual adoption of Next.js specific features.
Please share any feedback related to this transform [in this discussion](https://github.com/vercel/next.js/discussions/25858).
### [10](#10)
#### [Add React imports](#add-react-imports)
##### [`add-missing-react-import`](#add-missing-react-import)
Terminal
npx @next/codemod add-missing-react-import
Transforms files that do not import `React` to include the import in order for the new [React JSX transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) to work.
For example:
my-component.js
export default class Home extends React.Component {
render() {
return <div>Hello World</div>
}
}
Transforms into:
my-component.js
import React from 'react'
export default class Home extends React.Component {
render() {
return <div>Hello World</div>
}
}
### [9](#9)
#### [Transform Anonymous Components into Named Components](#transform-anonymous-components-into-named-components)
##### [`name-default-component`](#name-default-component)
Terminal
npx @next/codemod name-default-component
**Versions 9 and above.**
Transforms anonymous components into named components to make sure they work with [Fast Refresh](https://nextjs.org/blog/next-9-4#fast-refresh).
For example:
my-component.js
export default function () {
return <div>Hello World</div>
}
Transforms into:
my-component.js
export default function MyComponent() {
return <div>Hello World</div>
}
The component will have a camel-cased name based on the name of the file, and it also works with arrow functions.
### [8](#8)
#### [Transform AMP HOC into page config](#transform-amp-hoc-into-page-config)
##### [`withamp-to-config`](#withamp-to-config)
Terminal
npx @next/codemod withamp-to-config
Transforms the `withAmp` HOC into Next.js 9 page configuration.
For example:
// Before
import { withAmp } from 'next/amp'
function Home() {
return <h1>My AMP Page</h1>
}
export default withAmp(Home)
// After
export default function Home() {
return <h1>My AMP Page</h1>
}
export const config = {
amp: true,
}
### [6](#6)
#### [Use `withRouter`](#use-withrouter)
##### [`url-to-withrouter`](#url-to-withrouter)
Terminal
npx @next/codemod url-to-withrouter
Transforms the deprecated automatically injected `url` property on top level pages to using `withRouter` and the `router` property it injects. Read more here: [https://nextjs.org/docs/messages/url-deprecated](/docs/messages/url-deprecated)
For example:
From
import React from 'react'
export default class extends React.Component {
render() {
const { pathname } = this.props.url
return <div>Current pathname: {pathname}</div>
}
}
To
import React from 'react'
import { withRouter } from 'next/router'
export default withRouter(
class extends React.Component {
render() {
const { pathname } = this.props.router
return <div>Current pathname: {pathname}</div>
}
}
)
This is one case. All the cases that are transformed (and tested) can be found in the [`__testfixtures__` directory](https://github.com/vercel/next.js/tree/canary/packages/next-codemod/transforms/__testfixtures__/url-to-withrouter).
[Previous
Upgrading
](/docs/pages/building-your-application/upgrading)
[Next
From Pages to App
](/docs/pages/building-your-application/upgrading/app-router-migration)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"b7a28bbe852b56b44a9f0a6f78ed57bc\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/deploying/multi-zones | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [
Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [How to define a zone](#how-to-define-a-zone)
* [How to merge zones](#how-to-merge-zones)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/09-deploying/03-multi-zones.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Deploying](/docs/pages/building-your-application/deploying)Multi Zones
Multi Zones
===========
Examples
* [With Zones](https://github.com/vercel/next.js/tree/canary/examples/with-zones)
A zone is a single deployment of a Next.js app. You can have multiple zones and merge them as a single app.
For example, let's say you have the following apps:
* An app for serving `/blog/**`
* Another app for serving all other pages
With multi zones support, you can merge both these apps into a single one allowing your customers to browse it using a single URL, but you can develop and deploy both apps independently.
[How to define a zone](#how-to-define-a-zone)
---------------------------------------------
There are no zone related APIs. You only need to do the following:
* Make sure to keep only the pages you need in your app, meaning that an app can't have pages from another app, if app `A` has `/blog` then app `B` shouldn't have it too.
* Make sure to configure a [basePath](/docs/app/api-reference/next-config-js/basePath) to avoid conflicts with pages and static files.
[How to merge zones](#how-to-merge-zones)
-----------------------------------------
You can merge zones using [`rewrites`](/docs/pages/api-reference/next-config-js/rewrites) in one of the apps or any HTTP proxy.
For [Next.js on Vercel](https://vercel.com?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) applications, you can use a [monorepo](https://vercel.com/blog/monorepos-are-changing-how-teams-build-software?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) to deploy both apps with a single `git push`.
[Previous
Static Exports
](/docs/pages/building-your-application/deploying/static-exports)
[Next
Continuous Integration (CI) Build Caching
](/docs/pages/building-your-application/deploying/ci-build-caching)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"490f0038b909f000c702c35fee5eaa75\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[Building Your Application](/docs/pages/building-your-application)Upgrading
Upgrading
=========
Upgrade your application to newer versions of Next.js or migrate from the Pages Router to the App Router.
[
### Codemods
Use codemods to upgrade your Next.js codebase when new features are released.
](/docs/pages/building-your-application/upgrading/codemods)[
### From Pages to App
Learn how to upgrade your existing Next.js application from the Pages Router to the App Router.
](/docs/pages/building-your-application/upgrading/app-router-migration)[
### Migrating from Vite
Learn how to migrate your existing React application from Vite to Next.js.
](/docs/pages/building-your-application/upgrading/from-vite)[
### Migrating from Create React App
Learn how to migrate your existing React application from Create React App to Next.js.
](/docs/pages/building-your-application/upgrading/from-create-react-app)[
### Version 14
Upgrade your Next.js Application from Version 13 to 14.
](/docs/pages/building-your-application/upgrading/version-14)[
### Version 13
Upgrade your Next.js Application from Version 12 to 13.
](/docs/pages/building-your-application/upgrading/version-13)[
### Version 12
Upgrade your Next.js Application from Version 11 to Version 12.
](/docs/pages/building-your-application/upgrading/version-12)[
### Version 11
Upgrade your Next.js Application from Version 10 to Version 11.
](/docs/pages/building-your-application/upgrading/version-11)[
### Version 10
Upgrade your Next.js Application from Version 9 to Version 10.
](/docs/pages/building-your-application/upgrading/version-10)[
### Version 9
Upgrade your Next.js Application from Version 8 to Version 9.
](/docs/pages/building-your-application/upgrading/version-9)
[Previous
Continuous Integration (CI) Build Caching
](/docs/pages/building-your-application/deploying/ci-build-caching)
[Next
Codemods
](/docs/pages/building-your-application/upgrading/codemods)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"2e3929ffec39b65c53f4a75d2d232450\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/deploying/ci-build-caching | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [
Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Vercel](#vercel)
* [CircleCI](#circleci)
* [Travis CI](#travis-ci)
* [GitLab CI](#gitlab-ci)
* [Netlify CI](#netlify-ci)
* [AWS CodeBuild](#aws-codebuild)
* [GitHub Actions](#github-actions)
* [Bitbucket Pipelines](#bitbucket-pipelines)
* [Heroku](#heroku)
* [Azure Pipelines](#azure-pipelines)
* [Jenkins (Pipeline)](#jenkins-pipeline)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/09-deploying/04-ci-build-caching.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Deploying](/docs/pages/building-your-application/deploying)Continuous Integration (CI) Build Caching
Continuous Integration (CI) Build Caching
=========================================
To improve build performance, Next.js saves a cache to `.next/cache` that is shared between builds.
To take advantage of this cache in Continuous Integration (CI) environments, your CI workflow will need to be configured to correctly persist the cache between builds.
> If your CI is not configured to persist `.next/cache` between builds, you may see a [No Cache Detected](/docs/messages/no-cache) error.
Here are some example cache configurations for common CI providers:
[Vercel](#vercel)
-----------------
Next.js caching is automatically configured for you. There's no action required on your part.
[CircleCI](#circleci)
---------------------
Edit your `save_cache` step in `.circleci/config.yml` to include `.next/cache`:
steps:
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- ./.next/cache
If you do not have a `save_cache` key, please follow CircleCI's [documentation on setting up build caching](https://circleci.com/docs/2.0/caching/).
[Travis CI](#travis-ci)
-----------------------
Add or merge the following into your `.travis.yml`:
cache:
directories:
- $HOME/.cache/yarn
- node_modules
- .next/cache
[GitLab CI](#gitlab-ci)
-----------------------
Add or merge the following into your `.gitlab-ci.yml`:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .next/cache/
[Netlify CI](#netlify-ci)
-------------------------
Use [Netlify Plugins](https://www.netlify.com/products/build/plugins/) with [`@netlify/plugin-nextjs`](https://www.npmjs.com/package/@netlify/plugin-nextjs).
[AWS CodeBuild](#aws-codebuild)
-------------------------------
Add (or merge in) the following to your `buildspec.yml`:
cache:
paths:
- 'node_modules/**/*' # Cache `node_modules` for faster `yarn` or `npm i`
- '.next/cache/**/*' # Cache Next.js for faster application rebuilds
[GitHub Actions](#github-actions)
---------------------------------
Using GitHub's [actions/cache](https://github.com/actions/cache), add the following step in your workflow file:
uses: actions/cache@v4
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
[Bitbucket Pipelines](#bitbucket-pipelines)
-------------------------------------------
Add or merge the following into your `bitbucket-pipelines.yml` at the top level (same level as `pipelines`):
definitions:
caches:
nextcache: .next/cache
Then reference it in the `caches` section of your pipeline's `step`:
- step:
name: your_step_name
caches:
- node
- nextcache
[Heroku](#heroku)
-----------------
Using Heroku's [custom cache](https://devcenter.heroku.com/articles/nodejs-support#custom-caching), add a `cacheDirectories` array in your top-level package.json:
"cacheDirectories": [".next/cache"]
[Azure Pipelines](#azure-pipelines)
-----------------------------------
Using Azure Pipelines' [Cache task](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/cache), add the following task to your pipeline yaml file somewhere prior to the task that executes `next build`:
- task: Cache@2
displayName: 'Cache .next/cache'
inputs:
key: next | $(Agent.OS) | yarn.lock
path: '$(System.DefaultWorkingDirectory)/.next/cache'
[Jenkins (Pipeline)](#jenkins-pipeline)
---------------------------------------
Using Jenkins' [Job Cacher](https://www.jenkins.io/doc/pipeline/steps/jobcacher/) plugin, add the following build step to your `Jenkinsfile` where you would normally run `next build` or `npm install`:
stage("Restore npm packages") {
steps {
// Writes lock-file to cache based on the GIT_COMMIT hash
writeFile file: "next-lock.cache", text: "$GIT_COMMIT"
cache(caches: [
arbitraryFileCache(
path: "node_modules",
includes: "**/*",
cacheValidityDecidingFile: "package-lock.json"
)
]) {
sh "npm install"
}
}
}
stage("Build") {
steps {
// Writes lock-file to cache based on the GIT_COMMIT hash
writeFile file: "next-lock.cache", text: "$GIT_COMMIT"
cache(caches: [
arbitraryFileCache(
path: ".next/cache",
includes: "**/*",
cacheValidityDecidingFile: "next-lock.cache"
)
]) {
// aka `next build`
sh "npm run build"
}
}
}
[Previous
Multi Zones
](/docs/pages/building-your-application/deploying/multi-zones)
[Next
Upgrading
](/docs/pages/building-your-application/upgrading)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"c402928d8763f1fb83013e4035391729\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-14 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [
Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Upgrading from 13 to 14](#upgrading-from-13-to-14)
* [v14 Summary](#v14-summary)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/05-version-14.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 14
Version 14
==========
[Upgrading from 13 to 14](#upgrading-from-13-to-14)
---------------------------------------------------
To update to Next.js version 14, run the following command using your preferred package manager:
Terminal
npm i next@latest react@latest react-dom@latest eslint-config-next@latest
Terminal
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest
Terminal
pnpm up next react react-dom eslint-config-next --latest
Terminal
bun add next@latest react@latest react-dom@latest eslint-config-next@latest
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their latest versions.
### [v14 Summary](#v14-summary)
* The minimum Node.js version has been bumped from 16.14 to 18.17, since 16.x has reached end-of-life.
* The `next export` command has been removed in favor of `output: 'export'` config. Please see the [docs](https://nextjs.org/docs/app/building-your-application/deploying/static-exports) for more information.
* The `next/server` import for `ImageResponse` was renamed to `next/og`. A [codemod is available](/docs/app/building-your-application/upgrading/codemods#next-og-import) to safely and automatically rename your imports.
* The `@next/font` package has been fully removed in favor of the built-in `next/font`. A [codemod is available](/docs/app/building-your-application/upgrading/codemods#built-in-next-font) to safely and automatically rename your imports.
* The WASM target for `next-swc` has been removed.
[Previous
Migrating from Create React App
](/docs/pages/building-your-application/upgrading/from-create-react-app)
[Next
Version 13
](/docs/pages/building-your-application/upgrading/version-13)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"5107eee81996e81f37dfa48200946ca2\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/deploying/static-exports | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [
Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Configuration](#configuration)
* [Supported Features](#supported-features-1)
* [Image Optimization](#image-optimization)
* [Unsupported Features](#unsupported-features)
* [Deploying](#deploying)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/09-deploying/02-static-exports.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Deploying](/docs/pages/building-your-application/deploying)Static Exports
Static Exports
==============
Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.
When running `next build`, Next.js generates an HTML file per route. By breaking a strict SPA into individual HTML files, Next.js can avoid loading unnecessary JavaScript code on the client-side, reducing the bundle size and enabling faster page loads.
Since Next.js supports this static export, it can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets.
> **Good to know**: We recommend using the App Router for enhanced static export support.
[Configuration](#configuration)
-------------------------------
To enable a static export, change the output mode inside `next.config.js`:
next.config.js
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: 'export',
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true,
// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
// skipTrailingSlashRedirect: true,
// Optional: Change the output directory `out` -> `dist`
// distDir: 'dist',
}
module.exports = nextConfig
After running `next build`, Next.js will produce an `out` folder which contains the HTML/CSS/JS assets for your application.
You can utilize [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) and [`getStaticPaths`](/docs/pages/building-your-application/data-fetching/get-static-paths) to generate an HTML file for each page in your `pages` directory (or more for [dynamic routes](/docs/app/building-your-application/routing/dynamic-routes)).
[Supported Features](#supported-features-1)
-------------------------------------------
The majority of core Next.js features needed to build a static site are supported, including:
* [Dynamic Routes when using `getStaticPaths`](/docs/app/building-your-application/routing/dynamic-routes)
* Prefetching with `next/link`
* Preloading JavaScript
* [Dynamic Imports](/docs/pages/building-your-application/optimizing/lazy-loading)
* Any styling options (e.g. CSS Modules, styled-jsx)
* [Client-side data fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props)
* [`getStaticPaths`](/docs/pages/building-your-application/data-fetching/get-static-paths)
### [Image Optimization](#image-optimization)
[Image Optimization](/docs/app/building-your-application/optimizing/images) through `next/image` can be used with a static export by defining a custom image loader in `next.config.js`. For example, you can optimize images with a service like Cloudinary:
next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
images: {
loader: 'custom',
loaderFile: './my-loader.ts',
},
}
module.exports = nextConfig
This custom loader will define how to fetch images from a remote source. For example, the following loader will construct the URL for Cloudinary:
my-loader.ts
TypeScript
JavaScriptTypeScript
export default function cloudinaryLoader({
src,
width,
quality,
}: {
src: string
width: number
quality?: number
}) {
const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`]
return `https://res.cloudinary.com/demo/image/upload/${params.join(
','
)}${src}`
}
You can then use `next/image` in your application, defining relative paths to the image in Cloudinary:
app/page.tsx
TypeScript
JavaScriptTypeScript
import Image from 'next/image'
export default function Page() {
return <Image alt="turtles" src="/turtles.jpg" width={300} height={300} />
}
[Unsupported Features](#unsupported-features)
---------------------------------------------
Features that require a Node.js server, or dynamic logic that cannot be computed during the build process, are **not** supported:
* [Internationalized Routing](/docs/pages/building-your-application/routing/internationalization)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Redirects](/docs/pages/api-reference/next-config-js/redirects)
* [Headers](/docs/pages/api-reference/next-config-js/headers)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Image Optimization](/docs/pages/building-your-application/optimizing/images) with the default `loader`
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [`getStaticPaths` with `fallback: true`](/docs/pages/api-reference/functions/get-static-paths#fallback-true)
* [`getStaticPaths` with `fallback: 'blocking'`](/docs/pages/api-reference/functions/get-static-paths#fallback-blocking)
* [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props)
[Deploying](#deploying)
-----------------------
With a static export, Next.js can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets.
When running `next build`, Next.js generates the static export into the `out` folder. For example, let's say you have the following routes:
* `/`
* `/blog/[id]`
After running `next build`, Next.js will generate the following files:
* `/out/index.html`
* `/out/404.html`
* `/out/blog/post-1.html`
* `/out/blog/post-2.html`
If you are using a static host like Nginx, you can configure rewrites from incoming requests to the correct files:
nginx.conf
server {
listen 80;
server_name acme.com;
root /var/www/out;
location / {
try_files $uri $uri.html $uri/ =404;
}
# This is necessary when `trailingSlash: false`.
# You can omit this when `trailingSlash: true`.
location /blog/ {
rewrite ^/blog/(.*)$ /blog/$1.html break;
}
error_page 404 /404.html;
location = /404.html {
internal;
}
}
[Version History](#version-history)
-----------------------------------
Version
Changes
`v14.0.0`
`next export` has been removed in favor of `"output": "export"`
`v13.4.0`
App Router (Stable) adds enhanced static export support, including using React Server Components and Route Handlers.
`v13.3.0`
`next export` is deprecated and replaced with `"output": "export"`
[Previous
Production Checklist
](/docs/pages/building-your-application/deploying/production-checklist)
[Next
Multi Zones
](/docs/pages/building-your-application/deploying/multi-zones)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"c9cb5f662cc73ca333ec4ed4d51685b4\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/from-vite | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [
Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Why Switch?](#why-switch)
* [Slow initial page loading time](#slow-initial-page-loading-time)
* [No automatic code splitting](#no-automatic-code-splitting)
* [Network waterfalls](#network-waterfalls)
* [Fast and intentional loading states](#fast-and-intentional-loading-states)
* [Choose the data fetching strategy](#choose-the-data-fetching-strategy)
* [Middleware](#middleware)
* [Built-in Optimizations](#built-in-optimizations)
* [Migration Steps](#migration-steps)
* [Step 1: Install the Next.js Dependency](#step-1-install-the-nextjs-dependency)
* [Step 2: Create the Next.js Configuration File](#step-2-create-the-nextjs-configuration-file)
* [Step 3: Update TypeScript Configuration](#step-3-update-typescript-configuration)
* [Step 4: Create the Root Layout](#step-4-create-the-root-layout)
* [Step 5: Create the Entrypoint Page](#step-5-create-the-entrypoint-page)
* [Step 6: Update Static Image Imports](#step-6-update-static-image-imports)
* [Step 7: Migrate the Environment Variables](#step-7-migrate-the-environment-variables)
* [Step 8: Update Scripts in package.json](#step-8-update-scripts-in-packagejson)
* [Step 9: Clean Up](#step-9-clean-up)
* [Next Steps](#next-steps)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/03-from-vite.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Migrating from Vite
Migrating from Vite
===================
This guide will help you migrate an existing Vite application to Next.js.
[Why Switch?](#why-switch)
--------------------------
There are several reasons why you might want to switch from Vite to Next.js:
### [Slow initial page loading time](#slow-initial-page-loading-time)
If you have built your application with the [default Vite plugin for React](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react), your application is a purely client-side application. Client-side only applications, also known as single-page applications (SPAs), often experience slow initial page loading time. This happens due to a couple of reasons:
1. The browser needs to wait for the React code and your entire application bundle to download and run before your code is able to send requests to load some data.
2. Your application code grows with every new feature and extra dependency you add.
### [No automatic code splitting](#no-automatic-code-splitting)
The previous issue of slow loading times can be somewhat managed with code splitting. However, if you try to do code splitting manually, you'll often make performance worse. It's easy to inadvertently introduce network waterfalls when code-splitting manually. Next.js provides automatic code splitting built into its router.
### [Network waterfalls](#network-waterfalls)
A common cause of poor performance occurs when applications make sequential client-server requests to fetch data. One common pattern for data fetching in an SPA is to initially render a placeholder, and then fetch data after the component has mounted. Unfortunately, this means that a child component that fetches data can't start fetching until the parent component has finished loading its own data.
While fetching data on the client is supported with Next.js, it also gives you the option to shift data fetching to the server, which can eliminate client-server waterfalls.
### [Fast and intentional loading states](#fast-and-intentional-loading-states)
With built-in support for [streaming through React Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense), you can be more intentional about which parts of your UI you want to load first and in what order without introducing network waterfalls.
This enables you to build pages that are faster to load and eliminate [layout shifts](https://vercel.com/blog/how-core-web-vitals-affect-seo).
### [Choose the data fetching strategy](#choose-the-data-fetching-strategy)
Depending on your needs, Next.js allows you to choose your data fetching strategy on a page and component basis. You can decide to fetch at build time, at request time on the server, or on the client. For example, you can fetch data from your CMS and render your blog posts at build time, which can then be efficiently cached on a CDN.
### [Middleware](#middleware)
[Next.js Middleware](/docs/app/building-your-application/routing/middleware) allows you to run code on the server before a request is completed. This is especially useful to avoid having a flash of unauthenticated content when the user visits an authenticated-only page by redirecting the user to a login page. The middleware is also useful for experimentation and [internationalization](/docs/app/building-your-application/routing/internationalization).
### [Built-in Optimizations](#built-in-optimizations)
[Images](/docs/app/building-your-application/optimizing/images), [fonts](/docs/app/building-your-application/optimizing/fonts), and [third-party scripts](/docs/app/building-your-application/optimizing/scripts) often have significant impact on an application's performance. Next.js comes with built-in components that automatically optimize those for you.
[Migration Steps](#migration-steps)
-----------------------------------
Our goal with this migration is to get a working Next.js application as quickly as possible, so that you can then adopt Next.js features incrementally. To begin with, we'll keep it as a purely client-side application (SPA) without migrating your existing router. This helps minimize the chances of encountering issues during the migration process and reduces merge conflicts.
### [Step 1: Install the Next.js Dependency](#step-1-install-the-nextjs-dependency)
The first thing you need to do is to install `next` as a dependency:
Terminal
npm install next@latest
### [Step 2: Create the Next.js Configuration File](#step-2-create-the-nextjs-configuration-file)
Create a `next.config.mjs` at the root of your project. This file will hold your [Next.js configuration options](/docs/app/api-reference/next-config-js).
next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // Outputs a Single-Page Application (SPA).
distDir: './dist', // Changes the build output directory to `./dist/`.
}
export default nextConfig
> **Good to know:** You can use either `.js` or `.mjs` for your Next.js configuration file.
### [Step 3: Update TypeScript Configuration](#step-3-update-typescript-configuration)
If you're using TypeScript, you need to update your `tsconfig.json` file with the following changes to make it compatible with Next.js. If you're not using TypeScript, you can skip this step.
1. Remove the [project reference](https://www.typescriptlang.org/tsconfig#references) to `tsconfig.node.json`
2. Add `./dist/types/**/*.ts` and `./next-env.d.ts` to the [`include` array](https://www.typescriptlang.org/tsconfig#include)
3. Add `./node_modules` to the [`exclude` array](https://www.typescriptlang.org/tsconfig#exclude)
4. Add `{ "name": "next" }` to the [`plugins` array in `compilerOptions`](https://www.typescriptlang.org/tsconfig#plugins): `"plugins": [{ "name": "next" }]`
5. Set [`esModuleInterop`](https://www.typescriptlang.org/tsconfig#esModuleInterop) to `true`: `"esModuleInterop": true`
6. Set [`jsx`](https://www.typescriptlang.org/tsconfig#jsx) to `preserve`: `"jsx": "preserve"`
7. Set [`allowJs`](https://www.typescriptlang.org/tsconfig#allowJs) to `true`: `"allowJs": true`
8. Set [`forceConsistentCasingInFileNames`](https://www.typescriptlang.org/tsconfig#forceConsistentCasingInFileNames) to `true`: `"forceConsistentCasingInFileNames": true`
9. Set [`incremental`](https://www.typescriptlang.org/tsconfig#incremental) to `true`: `"incremental": true`
Here's an example of a working `tsconfig.json` with those changes:
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"plugins": [{ "name": "next" }]
},
"include": ["./src", "./dist/types/**/*.ts", "./next-env.d.ts"],
"exclude": ["./node_modules"]
}
You can find more information about configuring TypeScript on the [Next.js docs](/docs/app/building-your-application/configuring/typescript#typescript-plugin).
### [Step 4: Create the Root Layout](#step-4-create-the-root-layout)
A Next.js [App Router](/docs/app) application must include a [root layout](/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) file, which is a [React Server Component](/docs/app/building-your-application/rendering/server-components) that will wrap all pages in your application. This file is defined at the top level of the `app` directory.
The closest equivalent to the root layout file in a Vite application is the [`index.html` file](https://vitejs.dev/guide/#index-html-and-project-root), which contains your `<html>`, `<head>`, and `<body>` tags.
In this step, you'll convert your `index.html` file into a root layout file:
1. Create a new `app` directory in your `src` directory.
2. Create a new `layout.tsx` file inside that `app` directory:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return null
}
> **Good to know**: `.js`, `.jsx`, or `.tsx` extensions can be used for Layout files.
3. Copy the content of your `index.html` file into the previously created `<RootLayout>` component while replacing the `body.div#root` and `body.script` tags with `<div id="root">{children}</div>`:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My App</title>
<meta name="description" content="My App is a..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
4. Next.js already includes by default the [meta charset](https://developer.mozilla.org/docs/Web/HTML/Element/meta#charset) and [meta viewport](https://developer.mozilla.org/docs/Web/HTML/Viewport_meta_tag) tags, so you can safely remove those from your `<head>`:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
<title>My App</title>
<meta name="description" content="My App is a..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
5. Any [metadata files](/docs/app/building-your-application/optimizing/metadata#file-based-metadata) such as `favicon.ico`, `icon.png`, `robots.txt` are automatically added to the application `<head>` tag as long as you have them placed into the top level of the `app` directory. After moving [all supported files](/docs/app/building-your-application/optimizing/metadata#file-based-metadata) into the `app` directory you can safely delete their `<link>` tags:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<title>My App</title>
<meta name="description" content="My App is a..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
6. Finally, Next.js can manage your last `<head>` tags with the [Metadata API](/docs/app/building-your-application/optimizing/metadata). Move your final metadata info into an exported [`metadata` object](/docs/app/api-reference/functions/generate-metadata#metadata-object):
app/layout.tsx
TypeScript
JavaScriptTypeScript
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'My App',
description: 'My App is a...',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
With the above changes, you shifted from declaring everything in your `index.html` to using Next.js' convention-based approach built into the framework ([Metadata API](/docs/app/building-your-application/optimizing/metadata)). This approach enables you to more easily improve your SEO and web shareability of your pages.
### [Step 5: Create the Entrypoint Page](#step-5-create-the-entrypoint-page)
On Next.js you declare an entrypoint for your application by creating a `page.tsx` file. The closest equivalent of this file on Vite is your `main.tsx` file. In this step, you’ll set up the entrypoint of your application.
1. **Create a `[[...slug]]` directory in your `app` directory.**
Since in this guide we're aiming first to set up our Next.js as an SPA (Single Page Application), you need your page entrypoint to catch all possible routes of your application. For that, create a new `[[...slug]]` directory in your `app` directory.
This directory is what is called an [optional catch-all route segment](/docs/app/building-your-application/routing/dynamic-routes#optional-catch-all-segments). Next.js uses a file-system based router where [directories are used to define routes](/docs/app/building-your-application/routing/defining-routes#creating-routes). This special directory will make sure that all routes of your application will be directed to its containing `page.tsx` file.
2. **Create a new `page.tsx` file inside the `app/[[...slug]]` directory with the following content:**
app/\[\[...slug\]\]/page.tsx
TypeScript
JavaScriptTypeScript
import '../../index.css'
export function generateStaticParams() {
return [{ slug: [''] }]
}
export default function Page() {
return '...' // We'll update this
}
> **Good to know**: `.js`, `.jsx`, or `.tsx` extensions can be used for Page files.
This file is a [Server Component](/docs/app/building-your-application/rendering/server-components). When you run `next build`, the file is prerendered into a static asset. It does _not_ require any dynamic code.
This file imports our global CSS and tells [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) we are only going to generate one route, the index route at `/`.
Now, let's move the rest of our Vite application which will run client-only.
app/\[\[...slug\]\]/client.tsx
TypeScript
JavaScriptTypeScript
'use client'
import React from 'react'
import dynamic from 'next/dynamic'
const App = dynamic(() => import('../../App'), { ssr: false })
export function ClientOnly() {
return <App />
}
This file is a [Client Component](/docs/app/building-your-application/rendering/client-components), defined by the `'use client'` directive. Client Components are still [prerendered to HTML](/docs/app/building-your-application/rendering/client-components#how-are-client-components-rendered) on the server before being sent to the client.
Since we want a client-only application to start, we can configure Next.js to disable prerendering from the `App` component down.
const App = dynamic(() => import('../../App'), { ssr: false })
Now, update your entrypoint page to use the new component:
app/\[\[...slug\]\]/page.tsx
TypeScript
JavaScriptTypeScript
import '../../index.css'
import { ClientOnly } from './client'
export function generateStaticParams() {
return [{ slug: [''] }]
}
export default function Page() {
return <ClientOnly />
}
### [Step 6: Update Static Image Imports](#step-6-update-static-image-imports)
Next.js handles static image imports slightly different from Vite. With Vite, importing an image file will return its public URL as a string:
App.tsx
import image from './img.png' // `image` will be '/assets/img.2d8efhg.png' in production
export default function App() {
return <img src={image} />
}
With Next.js, static image imports return an object. The object can then be used directly with the Next.js [`<Image>` component](/docs/app/api-reference/components/image), or you can use the object's `src` property with your existing `<img>` tag.
The `<Image>` component has the added benefits of [automatic image optimization](/docs/app/building-your-application/optimizing/images). The `<Image>` component automatically sets the `width` and `height` attributes of the resulting `<img>` based on the image's dimensions. This prevents layout shifts when the image loads. However, this can cause issues if your app contains images with only one of their dimensions being styled without the other styled to `auto`. When not styled to `auto`, the dimension will default to the `<img>` dimension attribute's value, which can cause the image to appear distorted.
Keeping the `<img>` tag will reduce the amount of changes in your application and prevent the above issues. You can then optionally later migrate to the `<Image>` component to take advantage of optimizing images by [configuring a loader](/docs/app/building-your-application/optimizing/images#loaders), or moving to the default Next.js server which has automatic image optimization.
1. **Convert absolute import paths for images imported from `/public` into relative imports:**
// Before
import logo from '/logo.png'
// After
import logo from '../public/logo.png'
2. **Pass the image `src` property instead of the whole image object to your `<img>` tag:**
// Before
<img src={logo} />
// After
<img src={logo.src} />
Alternatively, you can reference the public URL for the image asset based on the filename. For example, `public/logo.png` will serve the image at `/logo.png` for your application, which would be the `src` value.
> **Warning:** If you're using TypeScript, you might encounter type errors when accessing the `src` property. You can safely ignore those for now. They will be fixed by the end of this guide.
### [Step 7: Migrate the Environment Variables](#step-7-migrate-the-environment-variables)
Next.js has support for `.env` [environment variables](/docs/app/building-your-application/configuring/environment-variables) similar to Vite. The main difference is the prefix used to expose environment variables on the client-side.
* Change all environment variables with the `VITE_` prefix to `NEXT_PUBLIC_`.
Vite exposes a few built-in environment variables on the special `import.meta.env` object which aren’t supported by Next.js. You need to update their usage as follows:
* `import.meta.env.MODE` ⇒ `process.env.NODE_ENV`
* `import.meta.env.PROD` ⇒ `process.env.NODE_ENV === 'production'`
* `import.meta.env.DEV` ⇒ `process.env.NODE_ENV !== 'production'`
* `import.meta.env.SSR` ⇒ `typeof window !== 'undefined'`
Next.js also doesn't provide a built-in `BASE_URL` environment variable. However, you can still configure one, if you need it:
1. **Add the following to your `.env` file:**
.env
# ...
NEXT_PUBLIC_BASE_PATH="/some-base-path"
2. **Set [`basePath`](/docs/app/api-reference/next-config-js/basePath) to `process.env.NEXT_PUBLIC_BASE_PATH` in your `next.config.mjs` file:**
next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // Outputs a Single-Page Application (SPA).
distDir: './dist', // Changes the build output directory to `./dist/`.
basePath: process.env.NEXT_PUBLIC_BASE_PATH, // Sets the base path to `/some-base-path`.
}
export default nextConfig
3. **Update `import.meta.env.BASE_URL` usages to `process.env.NEXT_PUBLIC_BASE_PATH`**
### [Step 8: Update Scripts in `package.json`](#step-8-update-scripts-in-packagejson)
You should now be able to run your application to test if you successfully migrated to Next.js. But before that, you need to update your `scripts` in your `package.json` with Next.js related commands, and add `.next` and `next-env.d.ts` to your `.gitignore`:
package.json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
.gitignore
# ...
.next
next-env.d.ts
dist
Now run `npm run dev`, and open [`http://localhost:3000`](http://localhost:3000). You should see your application now running on Next.js.
> **Example:** Check out [this pull request](https://github.com/inngest/vite-to-nextjs/pull/1) for a working example of a Vite application migrated to Next.js.
### [Step 9: Clean Up](#step-9-clean-up)
You can now clean up your codebase from Vite related artifacts:
* Delete `main.tsx`
* Delete `index.html`
* Delete `vite-env.d.ts`
* Delete `tsconfig.node.json`
* Delete `vite.config.ts`
* Uninstall Vite dependencies
[Next Steps](#next-steps)
-------------------------
If everything went according to plan, you now have a functioning Next.js application running as a single-page application. However, you aren't yet taking advantage of most of Next.js' benefits, but you can now start making incremental changes to reap all the benefits. Here's what you might want to do next:
* Migrate from React Router to the [Next.js App Router](/docs/app/building-your-application/routing) to get:
* Automatic code splitting
* [Streaming Server-Rendering](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [React Server Components](/docs/app/building-your-application/rendering/server-components)
* [Optimize images with the `<Image>` component](/docs/app/building-your-application/optimizing/images)
* [Optimize fonts with `next/font`](/docs/app/building-your-application/optimizing/fonts)
* [Optimize third-party scripts with the `<Script>` component](/docs/app/building-your-application/optimizing/scripts)
* [Update your ESLint configuration to support Next.js rules](/docs/app/building-your-application/configuring/eslint)
[Previous
From Pages to App
](/docs/pages/building-your-application/upgrading/app-router-migration)
[Next
Migrating from Create React App
](/docs/pages/building-your-application/upgrading/from-create-react-app)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f2f0ee5e9f338576ede8920289062e6b\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/app-router-migration | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [
From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Upgrading](#upgrading)
* [Node.js Version](#nodejs-version)
* [Next.js Version](#nextjs-version)
* [ESLint Version](#eslint-version)
* [Next Steps](#next-steps)
* [Upgrading New Features](#upgrading-new-features)
* [<Image/> Component](#image-component)
* [<Link> Component](#link-component)
* [<Script> Component](#script-component)
* [Font Optimization](#font-optimization)
* [Migrating from pages to app](#migrating-from-pages-to-app)
* [Step 1: Creating the app directory](#step-1-creating-the-app-directory)
* [Step 2: Creating a Root Layout](#step-2-creating-a-root-layout)
* [Migrating \_document.js and \_app.js](#migrating-_documentjs-and-_appjs)
* [Migrating the getLayout() pattern to Layouts (Optional)](#migrating-the-getlayout-pattern-to-layouts-optional)
* [Step 3: Migrating next/head](#step-3-migrating-nexthead)
* [Step 4: Migrating Pages](#step-4-migrating-pages)
* [Step 5: Migrating Routing Hooks](#step-5-migrating-routing-hooks)
* [Step 6: Migrating Data Fetching Methods](#step-6-migrating-data-fetching-methods)
* [Server-side Rendering (getServerSideProps)](#server-side-rendering-getserversideprops)
* [Accessing Request Object](#accessing-request-object)
* [Static Site Generation (getStaticProps)](#static-site-generation-getstaticprops)
* [Dynamic paths (getStaticPaths)](#dynamic-paths-getstaticpaths)
* [Replacing fallback](#replacing-fallback)
* [Incremental Static Regeneration (getStaticProps with revalidate)](#incremental-static-regeneration-getstaticprops-with-revalidate)
* [API Routes](#api-routes)
* [Step 7: Styling](#step-7-styling)
* [Tailwind CSS](#tailwind-css)
* [Codemods](#codemods)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/02-app-router-migration.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)From Pages to App
From Pages to App
=================
This guide will help you:
* [Update your Next.js application from version 12 to version 13](#nextjs-version)
* [Upgrade features that work in both the `pages` and the `app` directories](#upgrading-new-features)
* [Incrementally migrate your existing application from `pages` to `app`](#migrating-from-pages-to-app)
[Upgrading](#upgrading)
-----------------------
### [Node.js Version](#nodejs-version)
The minimum Node.js version is now **v18.17**. See the [Node.js documentation](https://nodejs.org/docs/latest-v18.x/api/) for more information.
### [Next.js Version](#nextjs-version)
To update to Next.js version 13, run the following command using your preferred package manager:
Terminal
npm install next@latest react@latest react-dom@latest
### [ESLint Version](#eslint-version)
If you're using ESLint, you need to upgrade your ESLint version:
Terminal
npm install -D eslint-config-next@latest
> **Good to know**: You may need to restart the ESLint server in VS Code for the ESLint changes to take effect. Open the Command Palette (`cmd+shift+p` on Mac; `ctrl+shift+p` on Windows) and search for `ESLint: Restart ESLint Server`.
[Next Steps](#next-steps)
-------------------------
After you've updated, see the following sections for next steps:
* [Upgrade new features](#upgrading-new-features): A guide to help you upgrade to new features such as the improved Image and Link Components.
* [Migrate from the `pages` to `app` directory](#migrating-from-pages-to-app): A step-by-step guide to help you incrementally migrate from the `pages` to the `app` directory.
[Upgrading New Features](#upgrading-new-features)
-------------------------------------------------
Next.js 13 introduced the new [App Router](/docs/app/building-your-application/routing) with new features and conventions. The new Router is available in the `app` directory and co-exists with the `pages` directory.
Upgrading to Next.js 13 does **not** require using the new [App Router](/docs/app/building-your-application/routing#the-app-router). You can continue using `pages` with new features that work in both directories, such as the updated [Image component](#image-component), [Link component](#link-component), [Script component](#script-component), and [Font optimization](#font-optimization).
### [`<Image/>` Component](#image-component)
Next.js 12 introduced new improvements to the Image Component with a temporary import: `next/future/image`. These improvements included less client-side JavaScript, easier ways to extend and style images, better accessibility, and native browser lazy loading.
In version 13, this new behavior is now the default for `next/image`.
There are two codemods to help you migrate to the new Image Component:
* [**`next-image-to-legacy-image` codemod**](/docs/app/building-your-application/upgrading/codemods#next-image-to-legacy-image): Safely and automatically renames `next/image` imports to `next/legacy/image`. Existing components will maintain the same behavior.
* [**`next-image-experimental` codemod**](/docs/app/building-your-application/upgrading/codemods#next-image-experimental): Dangerously adds inline styles and removes unused props. This will change the behavior of existing components to match the new defaults. To use this codemod, you need to run the `next-image-to-legacy-image` codemod first.
### [`<Link>` Component](#link-component)
The [`<Link>` Component](/docs/app/building-your-application/routing/linking-and-navigating#link-component) no longer requires manually adding an `<a>` tag as a child. This behavior was added as an experimental option in [version 12.2](https://nextjs.org/blog/next-12-2) and is now the default. In Next.js 13, `<Link>` always renders `<a>` and allows you to forward props to the underlying tag.
For example:
import Link from 'next/link'
// Next.js 12: `<a>` has to be nested otherwise it's excluded
<Link href="/about">
<a>About</a>
</Link>
// Next.js 13: `<Link>` always renders `<a>` under the hood
<Link href="/about">
About
</Link>
To upgrade your links to Next.js 13, you can use the [`new-link` codemod](/docs/app/building-your-application/upgrading/codemods#new-link).
### [`<Script>` Component](#script-component)
The behavior of [`next/script`](/docs/app/api-reference/components/script) has been updated to support both `pages` and `app`, but some changes need to be made to ensure a smooth migration:
* Move any `beforeInteractive` scripts you previously included in `_document.js` to the root layout file (`app/layout.tsx`).
* The experimental `worker` strategy does not yet work in `app` and scripts denoted with this strategy will either have to be removed or modified to use a different strategy (e.g. `lazyOnload`).
* `onLoad`, `onReady`, and `onError` handlers will not work in Server Components so make sure to move them to a [Client Component](/docs/app/building-your-application/rendering/server-components) or remove them altogether.
### [Font Optimization](#font-optimization)
Previously, Next.js helped you optimize fonts by [inlining font CSS](/docs/app/building-your-application/optimizing/fonts). Version 13 introduces the new [`next/font`](/docs/app/building-your-application/optimizing/fonts) module which gives you the ability to customize your font loading experience while still ensuring great performance and privacy. `next/font` is supported in both the `pages` and `app` directories.
While [inlining CSS](/docs/app/building-your-application/optimizing/fonts) still works in `pages`, it does not work in `app`. You should use [`next/font`](/docs/app/building-your-application/optimizing/fonts) instead.
See the [Font Optimization](/docs/app/building-your-application/optimizing/fonts) page to learn how to use `next/font`.
[Migrating from `pages` to `app`](#migrating-from-pages-to-app)
---------------------------------------------------------------
> **🎥 Watch:** Learn how to incrementally adopt the App Router → [YouTube (16 minutes)](https://www.youtube.com/watch?v=YQMSietiFm0).
Moving to the App Router may be the first time using React features that Next.js builds on top of such as Server Components, Suspense, and more. When combined with new Next.js features such as [special files](/docs/app/building-your-application/routing#file-conventions) and [layouts](/docs/app/building-your-application/routing/pages-and-layouts#layouts), migration means new concepts, mental models, and behavioral changes to learn.
We recommend reducing the combined complexity of these updates by breaking down your migration into smaller steps. The `app` directory is intentionally designed to work simultaneously with the `pages` directory to allow for incremental page-by-page migration.
* The `app` directory supports nested routes _and_ layouts. [Learn more](/docs/app/building-your-application/routing).
* Use nested folders to [define routes](/docs/app/building-your-application/routing/defining-routes) and a special `page.js` file to make a route segment publicly accessible. [Learn more](#step-4-migrating-pages).
* [Special file conventions](/docs/app/building-your-application/routing#file-conventions) are used to create UI for each route segment. The most common special files are `page.js` and `layout.js`.
* Use `page.js` to define UI unique to a route.
* Use `layout.js` to define UI that is shared across multiple routes.
* `.js`, `.jsx`, or `.tsx` file extensions can be used for special files.
* You can colocate other files inside the `app` directory such as components, styles, tests, and more. [Learn more](/docs/app/building-your-application/routing).
* Data fetching functions like `getServerSideProps` and `getStaticProps` have been replaced with [a new API](/docs/app/building-your-application/data-fetching) inside `app`. `getStaticPaths` has been replaced with [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params).
* `pages/_app.js` and `pages/_document.js` have been replaced with a single `app/layout.js` root layout. [Learn more](/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required).
* `pages/_error.js` has been replaced with more granular `error.js` special files. [Learn more](/docs/app/building-your-application/routing/error-handling).
* `pages/404.js` has been replaced with the [`not-found.js`](/docs/app/api-reference/file-conventions/not-found) file.
* `pages/api/*` API Routes have been replaced with the [`route.js`](/docs/app/api-reference/file-conventions/route) (Route Handler) special file.
### [Step 1: Creating the `app` directory](#step-1-creating-the-app-directory)
Update to the latest Next.js version (requires 13.4 or greater):
npm install next@latest
Then, create a new `app` directory at the root of your project (or `src/` directory).
### [Step 2: Creating a Root Layout](#step-2-creating-a-root-layout)
Create a new `app/layout.tsx` file inside the `app` directory. This is a [root layout](/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) that will apply to all routes inside `app`.
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
// Layouts must accept a children prop.
// This will be populated with nested layouts or pages
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
* The `app` directory **must** include a root layout.
* The root layout must define `<html>`, and `<body>` tags since Next.js does not automatically create them
* The root layout replaces the `pages/_app.tsx` and `pages/_document.tsx` files.
* `.js`, `.jsx`, or `.tsx` extensions can be used for layout files.
To manage `<head>` HTML elements, you can use the [built-in SEO support](/docs/app/building-your-application/optimizing/metadata):
app/layout.tsx
TypeScript
JavaScriptTypeScript
import { Metadata } from 'next'
export const metadata: Metadata = {
title: 'Home',
description: 'Welcome to Next.js',
}
#### [Migrating `_document.js` and `_app.js`](#migrating-_documentjs-and-_appjs)
If you have an existing `_app` or `_document` file, you can copy the contents (e.g. global styles) to the root layout (`app/layout.tsx`). Styles in `app/layout.tsx` will _not_ apply to `pages/*`. You should keep `_app`/`_document` while migrating to prevent your `pages/*` routes from breaking. Once fully migrated, you can then safely delete them.
If you are using any React Context providers, they will need to be moved to a [Client Component](/docs/app/building-your-application/rendering/client-components).
#### [Migrating the `getLayout()` pattern to Layouts (Optional)](#migrating-the-getlayout-pattern-to-layouts-optional)
Next.js recommended adding a [property to Page components](/docs/pages/building-your-application/routing/pages-and-layouts#layout-pattern#per-page-layouts) to achieve per-page layouts in the `pages` directory. This pattern can be replaced with native support for [nested layouts](/docs/app/building-your-application/routing/pages-and-layouts#layouts) in the `app` directory.
See before and after example
**Before**
components/DashboardLayout.js
export default function DashboardLayout({ children }) {
return (
<div>
<h2>My Dashboard</h2>
{children}
</div>
)
}
pages/dashboard/index.js
import DashboardLayout from '../components/DashboardLayout'
export default function Page() {
return <p>My Page</p>
}
Page.getLayout = function getLayout(page) {
return <DashboardLayout>{page}</DashboardLayout>
}
**After**
* Remove the `Page.getLayout` property from `pages/dashboard/index.js` and follow the [steps for migrating pages](#step-4-migrating-pages) to the `app` directory.
app/dashboard/page.js
export default function Page() {
return <p>My Page</p>
}
* Move the contents of `DashboardLayout` into a new [Client Component](/docs/app/building-your-application/rendering/client-components) to retain `pages` directory behavior.
app/dashboard/DashboardLayout.js
'use client' // this directive should be at top of the file, before any imports.
// This is a Client Component
export default function DashboardLayout({ children }) {
return (
<div>
<h2>My Dashboard</h2>
{children}
</div>
)
}
* Import the `DashboardLayout` into a new `layout.js` file inside the `app` directory.
app/dashboard/layout.js
import DashboardLayout from './DashboardLayout'
// This is a Server Component
export default function Layout({ children }) {
return <DashboardLayout>{children}</DashboardLayout>
}
* You can incrementally move non-interactive parts of `DashboardLayout.js` (Client Component) into `layout.js` (Server Component) to reduce the amount of component JavaScript you send to the client.
### [Step 3: Migrating `next/head`](#step-3-migrating-nexthead)
In the `pages` directory, the `next/head` React component is used to manage `<head>` HTML elements such as `title` and `meta` . In the `app` directory, `next/head` is replaced with the new [built-in SEO support](/docs/app/building-your-application/optimizing/metadata).
**Before:**
pages/index.tsx
TypeScript
JavaScriptTypeScript
import Head from 'next/head'
export default function Page() {
return (
<>
<Head>
<title>My page title</title>
</Head>
</>
)
}
**After:**
app/page.tsx
TypeScript
JavaScriptTypeScript
import { Metadata } from 'next'
export const metadata: Metadata = {
title: 'My Page Title',
}
export default function Page() {
return '...'
}
[See all metadata options](/docs/app/api-reference/functions/generate-metadata).
### [Step 4: Migrating Pages](#step-4-migrating-pages)
* Pages in the [`app` directory](/docs/app/building-your-application/routing) are [Server Components](/docs/app/building-your-application/rendering/server-components) by default. This is different from the `pages` directory where pages are [Client Components](/docs/app/building-your-application/rendering/client-components).
* [Data fetching](/docs/app/building-your-application/data-fetching) has changed in `app`. `getServerSideProps`, `getStaticProps` and `getInitialProps` have been replaced with a simpler API.
* The `app` directory uses nested folders to [define routes](/docs/app/building-your-application/routing/defining-routes) and a special `page.js` file to make a route segment publicly accessible.
* `pages` Directory
`app` Directory
Route
`index.js`
`page.js`
`/`
`about.js`
`about/page.js`
`/about`
`blog/[slug].js`
`blog/[slug]/page.js`
`/blog/post-1`
We recommend breaking down the migration of a page into two main steps:
* Step 1: Move the default exported Page Component into a new Client Component.
* Step 2: Import the new Client Component into a new `page.js` file inside the `app` directory.
> **Good to know**: This is the easiest migration path because it has the most comparable behavior to the `pages` directory.
**Step 1: Create a new Client Component**
* Create a new separate file inside the `app` directory (i.e. `app/home-page.tsx` or similar) that exports a Client Component. To define Client Components, add the `'use client'` directive to the top of the file (before any imports).
* Similar to the Pages Router, there is an [optimization step](/docs/app/building-your-application/rendering/client-components#full-page-load) to prerender Client Components to static HTML on the initial page load.
* Move the default exported page component from `pages/index.js` to `app/home-page.tsx`.
app/home-page.tsx
TypeScript
JavaScriptTypeScript
'use client'
// This is a Client Component (same as components in the `pages` directory)
// It receives data as props, has access to state and effects, and is
// prerendered on the server during the initial page load.
export default function HomePage({ recentPosts }) {
return (
<div>
{recentPosts.map((post) => (
<div key={post.id}>{post.title}</div>
))}
</div>
)
}
**Step 2: Create a new page**
* Create a new `app/page.tsx` file inside the `app` directory. This is a Server Component by default.
* Import the `home-page.tsx` Client Component into the page.
* If you were fetching data in `pages/index.js`, move the data fetching logic directly into the Server Component using the new [data fetching APIs](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating). See the [data fetching upgrade guide](#step-6-migrating-data-fetching-methods) for more details.
app/page.tsx
TypeScript
JavaScriptTypeScript
// Import your Client Component
import HomePage from './home-page'
async function getPosts() {
const res = await fetch('https://...')
const posts = await res.json()
return posts
}
export default async function Page() {
// Fetch data directly in a Server Component
const recentPosts = await getPosts()
// Forward fetched data to your Client Component
return <HomePage recentPosts={recentPosts} />
}
* If your previous page used `useRouter`, you'll need to update to the new routing hooks. [Learn more](/docs/app/api-reference/functions/use-router).
* Start your development server and visit [`http://localhost:3000`](http://localhost:3000). You should see your existing index route, now served through the app directory.
### [Step 5: Migrating Routing Hooks](#step-5-migrating-routing-hooks)
A new router has been added to support the new behavior in the `app` directory.
In `app`, you should use the three new hooks imported from `next/navigation`: [`useRouter()`](/docs/app/api-reference/functions/use-router), [`usePathname()`](/docs/app/api-reference/functions/use-pathname), and [`useSearchParams()`](/docs/app/api-reference/functions/use-search-params).
* The new `useRouter` hook is imported from `next/navigation` and has different behavior to the `useRouter` hook in `pages` which is imported from `next/router`.
* The [`useRouter` hook imported from `next/router`](/docs/pages/api-reference/functions/use-router) is not supported in the `app` directory but can continue to be used in the `pages` directory.
* The new `useRouter` does not return the `pathname` string. Use the separate `usePathname` hook instead.
* The new `useRouter` does not return the `query` object. Use the separate `useSearchParams` hook instead.
* You can use `useSearchParams` and `usePathname` together to listen to page changes. See the [Router Events](/docs/app/api-reference/functions/use-router#router-events) section for more details.
* These new hooks are only supported in Client Components. They cannot be used in Server Components.
app/example-client-component.tsx
TypeScript
JavaScriptTypeScript
'use client'
import { useRouter, usePathname, useSearchParams } from 'next/navigation'
export default function ExampleClientComponent() {
const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
// ...
}
In addition, the new `useRouter` hook has the following changes:
* `isFallback` has been removed because `fallback` has [been replaced](#replacing-fallback).
* The `locale`, `locales`, `defaultLocales`, `domainLocales` values have been removed because built-in i18n Next.js features are no longer necessary in the `app` directory. [Learn more about i18n](/docs/app/building-your-application/routing/internationalization).
* `basePath` has been removed. The alternative will not be part of `useRouter`. It has not yet been implemented.
* `asPath` has been removed because the concept of `as` has been removed from the new router.
* `isReady` has been removed because it is no longer necessary. During [static rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default), any component that uses the [`useSearchParams()`](/docs/app/api-reference/functions/use-search-params) hook will skip the prerendering step and instead be rendered on the client at runtime.
[View the `useRouter()` API reference](/docs/app/api-reference/functions/use-router).
### [Step 6: Migrating Data Fetching Methods](#step-6-migrating-data-fetching-methods)
The `pages` directory uses `getServerSideProps` and `getStaticProps` to fetch data for pages. Inside the `app` directory, these previous data fetching functions are replaced with a [simpler API](/docs/app/building-your-application/data-fetching) built on top of `fetch()` and `async` React Server Components.
app/page.tsx
TypeScript
JavaScriptTypeScript
export default async function Page() {
// This request should be cached until manually invalidated.
// Similar to `getStaticProps`.
// `force-cache` is the default and can be omitted.
const staticData = await fetch(`https://...`, { cache: 'force-cache' })
// This request should be refetched on every request.
// Similar to `getServerSideProps`.
const dynamicData = await fetch(`https://...`, { cache: 'no-store' })
// This request should be cached with a lifetime of 10 seconds.
// Similar to `getStaticProps` with the `revalidate` option.
const revalidatedData = await fetch(`https://...`, {
next: { revalidate: 10 },
})
return <div>...</div>
}
#### [Server-side Rendering (`getServerSideProps`)](#server-side-rendering-getserversideprops)
In the `pages` directory, `getServerSideProps` is used to fetch data on the server and forward props to the default exported React component in the file. The initial HTML for the page is prerendered from the server, followed by "hydrating" the page in the browser (making it interactive).
pages/dashboard.js
// `pages` directory
export async function getServerSideProps() {
const res = await fetch(`https://...`)
const projects = await res.json()
return { props: { projects } }
}
export default function Dashboard({ projects }) {
return (
<ul>
{projects.map((project) => (
<li key={project.id}>{project.name}</li>
))}
</ul>
)
}
In the `app` directory, we can colocate our data fetching inside our React components using [Server Components](/docs/app/building-your-application/rendering/server-components). This allows us to send less JavaScript to the client, while maintaining the rendered HTML from the server.
By setting the `cache` option to `no-store`, we can indicate that the fetched data should [never be cached](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating). This is similar to `getServerSideProps` in the `pages` directory.
app/dashboard/page.tsx
TypeScript
JavaScriptTypeScript
// `app` directory
// This function can be named anything
async function getProjects() {
const res = await fetch(`https://...`, { cache: 'no-store' })
const projects = await res.json()
return projects
}
export default async function Dashboard() {
const projects = await getProjects()
return (
<ul>
{projects.map((project) => (
<li key={project.id}>{project.name}</li>
))}
</ul>
)
}
#### [Accessing Request Object](#accessing-request-object)
In the `pages` directory, you can retrieve request-based data based on the Node.js HTTP API.
For example, you can retrieve the `req` object from `getServerSideProps` and use it to retrieve the request's cookies and headers.
pages/index.js
// `pages` directory
export async function getServerSideProps({ req, query }) {
const authHeader = req.getHeaders()['authorization'];
const theme = req.cookies['theme'];
return { props: { ... }}
}
export default function Page(props) {
return ...
}
The `app` directory exposes new read-only functions to retrieve request data:
* [`headers()`](/docs/app/api-reference/functions/headers): Based on the Web Headers API, and can be used inside [Server Components](/docs/app/building-your-application/rendering/server-components) to retrieve request headers.
* [`cookies()`](/docs/app/api-reference/functions/cookies): Based on the Web Cookies API, and can be used inside [Server Components](/docs/app/building-your-application/rendering/server-components) to retrieve cookies.
app/page.tsx
TypeScript
JavaScriptTypeScript
// `app` directory
import { cookies, headers } from 'next/headers'
async function getData() {
const authHeader = headers().get('authorization')
return '...'
}
export default async function Page() {
// You can use `cookies()` or `headers()` inside Server Components
// directly or in your data fetching function
const theme = cookies().get('theme')
const data = await getData()
return '...'
}
#### [Static Site Generation (`getStaticProps`)](#static-site-generation-getstaticprops)
In the `pages` directory, the `getStaticProps` function is used to pre-render a page at build time. This function can be used to fetch data from an external API or directly from a database, and pass this data down to the entire page as it's being generated during the build.
pages/index.js
// `pages` directory
export async function getStaticProps() {
const res = await fetch(`https://...`)
const projects = await res.json()
return { props: { projects } }
}
export default function Index({ projects }) {
return projects.map((project) => <div>{project.name}</div>)
}
In the `app` directory, data fetching with [`fetch()`](/docs/app/api-reference/functions/fetch) will default to `cache: 'force-cache'`, which will cache the request data until manually invalidated. This is similar to `getStaticProps` in the `pages` directory.
app/page.js
// `app` directory
// This function can be named anything
async function getProjects() {
const res = await fetch(`https://...`)
const projects = await res.json()
return projects
}
export default async function Index() {
const projects = await getProjects()
return projects.map((project) => <div>{project.name}</div>)
}
#### [Dynamic paths (`getStaticPaths`)](#dynamic-paths-getstaticpaths)
In the `pages` directory, the `getStaticPaths` function is used to define the dynamic paths that should be pre-rendered at build time.
pages/posts/\[id\].js
// `pages` directory
import PostLayout from '@/components/post-layout'
export async function getStaticPaths() {
return {
paths: [{ params: { id: '1' } }, { params: { id: '2' } }],
}
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
return { props: { post } }
}
export default function Post({ post }) {
return <PostLayout post={post} />
}
In the `app` directory, `getStaticPaths` is replaced with [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params).
[`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) behaves similarly to `getStaticPaths`, but has a simplified API for returning route parameters and can be used inside [layouts](/docs/app/building-your-application/routing/pages-and-layouts). The return shape of `generateStaticParams` is an array of segments instead of an array of nested `param` objects or a string of resolved paths.
app/posts/\[id\]/page.js
// `app` directory
import PostLayout from '@/components/post-layout'
export async function generateStaticParams() {
return [{ id: '1' }, { id: '2' }]
}
async function getPost(params) {
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
return post
}
export default async function Post({ params }) {
const post = await getPost(params)
return <PostLayout post={post} />
}
Using the name `generateStaticParams` is more appropriate than `getStaticPaths` for the new model in the `app` directory. The `get` prefix is replaced with a more descriptive `generate`, which sits better alone now that `getStaticProps` and `getServerSideProps` are no longer necessary. The `Paths` suffix is replaced by `Params`, which is more appropriate for nested routing with multiple dynamic segments.
* * *
#### [Replacing `fallback`](#replacing-fallback)
In the `pages` directory, the `fallback` property returned from `getStaticPaths` is used to define the behavior of a page that isn't pre-rendered at build time. This property can be set to `true` to show a fallback page while the page is being generated, `false` to show a 404 page, or `blocking` to generate the page at request time.
pages/posts/\[id\].js
// `pages` directory
export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking'
};
}
export async function getStaticProps({ params }) {
...
}
export default function Post({ post }) {
return ...
}
In the `app` directory the [`config.dynamicParams` property](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) controls how params outside of [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) are handled:
* **`true`**: (default) Dynamic segments not included in `generateStaticParams` are generated on demand.
* **`false`**: Dynamic segments not included in `generateStaticParams` will return a 404.
This replaces the `fallback: true | false | 'blocking'` option of `getStaticPaths` in the `pages` directory. The `fallback: 'blocking'` option is not included in `dynamicParams` because the difference between `'blocking'` and `true` is negligible with streaming.
app/posts/\[id\]/page.js
// `app` directory
export const dynamicParams = true;
export async function generateStaticParams() {
return [...]
}
async function getPost(params) {
...
}
export default async function Post({ params }) {
const post = await getPost(params);
return ...
}
With [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) set to `true` (the default), when a route segment is requested that hasn't been generated, it will be server-rendered and cached.
#### [Incremental Static Regeneration (`getStaticProps` with `revalidate`)](#incremental-static-regeneration-getstaticprops-with-revalidate)
In the `pages` directory, the `getStaticProps` function allows you to add a `revalidate` field to automatically regenerate a page after a certain amount of time.
pages/index.js
// `pages` directory
export async function getStaticProps() {
const res = await fetch(`https://.../posts`)
const posts = await res.json()
return {
props: { posts },
revalidate: 60,
}
}
export default function Index({ posts }) {
return (
<Layout>
<PostList posts={posts} />
</Layout>
)
}
In the `app` directory, data fetching with [`fetch()`](/docs/app/api-reference/functions/fetch) can use `revalidate`, which will cache the request for the specified amount of seconds.
app/page.js
// `app` directory
async function getPosts() {
const res = await fetch(`https://.../posts`, { next: { revalidate: 60 } })
const data = await res.json()
return data.posts
}
export default async function PostList() {
const posts = await getPosts()
return posts.map((post) => <div>{post.name}</div>)
}
#### [API Routes](#api-routes)
API Routes continue to work in the `pages/api` directory without any changes. However, they have been replaced by [Route Handlers](/docs/app/building-your-application/routing/route-handlers) in the `app` directory.
Route Handlers allow you to create custom request handlers for a given route using the Web [Request](https://developer.mozilla.org/docs/Web/API/Request) and [Response](https://developer.mozilla.org/docs/Web/API/Response) APIs.
app/api/route.ts
TypeScript
JavaScriptTypeScript
export async function GET(request: Request) {}
> **Good to know**: If you previously used API routes to call an external API from the client, you can now use [Server Components](/docs/app/building-your-application/rendering/server-components) instead to securely fetch data. Learn more about [data fetching](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating).
### [Step 7: Styling](#step-7-styling)
In the `pages` directory, global stylesheets are restricted to only `pages/_app.js`. With the `app` directory, this restriction has been lifted. Global styles can be added to any layout, page, or component.
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [Global Styles](/docs/app/building-your-application/styling/css-modules#global-styles)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [External Stylesheets](/docs/app/building-your-application/styling/css-modules#external-stylesheets)
* [Sass](/docs/app/building-your-application/styling/sass)
#### [Tailwind CSS](#tailwind-css)
If you're using Tailwind CSS, you'll need to add the `app` directory to your `tailwind.config.js` file:
tailwind.config.js
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx,mdx}', // <-- Add this line
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
],
}
You'll also need to import your global styles in your `app/layout.js` file:
app/layout.js
import '../styles/globals.css'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
Learn more about [styling with Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
[Codemods](#codemods)
---------------------
Next.js provides Codemod transformations to help upgrade your codebase when a feature is deprecated. See [Codemods](/docs/app/building-your-application/upgrading/codemods) for more information.
[Previous
Codemods
](/docs/pages/building-your-application/upgrading/codemods)
[Next
Migrating from Vite
](/docs/pages/building-your-application/upgrading/from-vite)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f5cb9fbca73062a253d38062e345e9b4\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-13 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [
Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Upgrading from 12 to 13](#upgrading-from-12-to-13)
* [v13 Summary](#v13-summary)
* [Migrating shared features](#migrating-shared-features)
* [<Image/> Component](#image-component)
* [<Link> Component](#link-component)
* [<Script> Component](#script-component)
* [Font Optimization](#font-optimization)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/06-version-13.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 13
Version 13
==========
[Upgrading from 12 to 13](#upgrading-from-12-to-13)
---------------------------------------------------
To update to Next.js version 13, run the following command using your preferred package manager:
Terminal
npm i next@13 react@latest react-dom@latest eslint-config-next@13
Terminal
yarn add next@13 react@latest react-dom@latest eslint-config-next@13
Terminal
pnpm i next@13 react@latest react-dom@latest eslint-config-next@13
Terminal
bun add next@13 react@latest react-dom@latest eslint-config-next@13
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their latest versions.
### [v13 Summary](#v13-summary)
* The [Supported Browsers](/docs/architecture/supported-browsers) have been changed to drop Internet Explorer and target modern browsers.
* The minimum Node.js version has been bumped from 12.22.0 to 16.14.0, since 12.x and 14.x have reached end-of-life.
* The minimum React version has been bumped from 17.0.2 to 18.2.0.
* The `swcMinify` configuration property was changed from `false` to `true`. See [Next.js Compiler](/docs/architecture/nextjs-compiler) for more info.
* The `next/image` import was renamed to `next/legacy/image`. The `next/future/image` import was renamed to `next/image`. A [codemod is available](/docs/pages/building-your-application/upgrading/codemods#next-image-to-legacy-image) to safely and automatically rename your imports.
* The `next/link` child can no longer be `<a>`. Add the `legacyBehavior` prop to use the legacy behavior or remove the `<a>` to upgrade. A [codemod is available](/docs/pages/building-your-application/upgrading/codemods#new-link) to automatically upgrade your code.
* The `target` configuration property has been removed and superseded by [Output File Tracing](/docs/pages/api-reference/next-config-js/output).
[Migrating shared features](#migrating-shared-features)
-------------------------------------------------------
Next.js 13 introduces a new [`app` directory](/docs/app/building-your-application/routing) with new features and conventions. However, upgrading to Next.js 13 does **not** require using the new [`app` directory](/docs/app/building-your-application/routing#the-app-router).
You can continue using `pages` with new features that work in both directories, such as the updated [Image component](#image-component), [Link component](#link-component), [Script component](#script-component), and [Font optimization](#font-optimization).
### [`<Image/>` Component](#image-component)
Next.js 12 introduced many improvements to the Image Component with a temporary import: `next/future/image`. These improvements included less client-side JavaScript, easier ways to extend and style images, better accessibility, and native browser lazy loading.
Starting in Next.js 13, this new behavior is now the default for `next/image`.
There are two codemods to help you migrate to the new Image Component:
* [next-image-to-legacy-image](/docs/pages/building-your-application/upgrading/codemods#next-image-to-legacy-image): This codemod will safely and automatically rename `next/image` imports to `next/legacy/image` to maintain the same behavior as Next.js 12. We recommend running this codemod to quickly update to Next.js 13 automatically.
* [next-image-experimental](/docs/pages/building-your-application/upgrading/codemods#next-image-experimental): After running the previous codemod, you can optionally run this experimental codemod to upgrade `next/legacy/image` to the new `next/image`, which will remove unused props and add inline styles. Please note this codemod is experimental and only covers static usage (such as `<Image src={img} layout="responsive" />`) but not dynamic usage (such as `<Image {...props} />`).
Alternatively, you can manually update by following the [migration guide](/docs/pages/building-your-application/upgrading/codemods#next-image-experimental) and also see the [legacy comparison](/docs/pages/api-reference/components/image-legacy#comparison).
### [`<Link>` Component](#link-component)
The [`<Link>` Component](/docs/pages/api-reference/components/link) no longer requires manually adding an `<a>` tag as a child. This behavior was added as an experimental option in [version 12.2](https://nextjs.org/blog/next-12-2) and is now the default. In Next.js 13, `<Link>` always renders `<a>` and allows you to forward props to the underlying tag.
For example:
import Link from 'next/link'
// Next.js 12: `<a>` has to be nested otherwise it's excluded
<Link href="/about">
<a>About</a>
</Link>
// Next.js 13: `<Link>` always renders `<a>` under the hood
<Link href="/about">
About
</Link>
To upgrade your links to Next.js 13, you can use the [`new-link` codemod](/docs/pages/building-your-application/upgrading/codemods#new-link).
### [`<Script>` Component](#script-component)
The behavior of [`next/script`](/docs/pages/api-reference/components/script) has been updated to support both `pages` and `app`. If incrementally adopting `app`, read the [upgrade guide](/docs/pages/building-your-application/upgrading).
### [Font Optimization](#font-optimization)
Previously, Next.js helped you optimize fonts by inlining font CSS. Version 13 introduces the new [`next/font`](/docs/pages/building-your-application/optimizing/fonts) module which gives you the ability to customize your font loading experience while still ensuring great performance and privacy.
See [Optimizing Fonts](/docs/pages/building-your-application/optimizing/fonts) to learn how to use `next/font`.
[Previous
Version 14
](/docs/pages/building-your-application/upgrading/version-14)
[Next
Version 12
](/docs/pages/building-your-application/upgrading/version-12)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"a3b955b2b79ffeb89f60b902a62c7b59\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-12 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [
Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Upgrading to 12.2](#upgrading-to-122)
* [Upgrading to 12.0](#upgrading-to-120)
* [SWC replacing Babel](#swc-replacing-babel)
* [SWC replacing Terser for minification](#swc-replacing-terser-for-minification)
* [Improvements to styled-jsx CSS parsing](#improvements-to-styled-jsx-css-parsing)
* [next/image changed wrapping element](#nextimage-changed-wrapping-element)
* [HMR connection now uses a WebSocket](#hmr-connection-now-uses-a-websocket)
* [Webpack 4 support has been removed](#webpack-4-support-has-been-removed)
* [target option deprecated](#target-option-deprecated)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/07-version-12.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 12
Version 12
==========
To upgrade to version 12, run the following command:
Terminal
npm i next@12 react@17 react-dom@17 eslint-config-next@12
Terminal
yarn add next@12 react@17 react-dom@17 eslint-config-next@12
Terminal
pnpm up next@12 react@17 react-dom@17 eslint-config-next@12
Terminal
bun add next@12 react@17 react-dom@17 eslint-config-next@12
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their corresponding versions.
### [Upgrading to 12.2](#upgrading-to-122)
[Middleware](/docs/messages/middleware-upgrade-guide) - If you were using Middleware prior to `12.2`, please see the [upgrade guide](/docs/messages/middleware-upgrade-guide) for more information.
### [Upgrading to 12.0](#upgrading-to-120)
[Minimum Node.js Version](https://nodejs.org/en/) - The minimum Node.js version has been bumped from `12.0.0` to `12.22.0` which is the first version of Node.js with native ES Modules support.
[Minimum React Version](https://react.dev/learn/add-react-to-an-existing-project) - The minimum required React version is `17.0.2`. To upgrade you can run the following command in the terminal:
Terminal
npm install react@latest react-dom@latest
yarn add react@latest react-dom@latest
pnpm update react@latest react-dom@latest
bun add react@latest react-dom@latest
#### [SWC replacing Babel](#swc-replacing-babel)
Next.js now uses the Rust-based compiler [SWC](https://swc.rs/) to compile JavaScript/TypeScript. This new compiler is up to 17x faster than Babel when compiling individual files and up to 5x faster Fast Refresh.
Next.js provides full backward compatibility with applications that have [custom Babel configuration](/docs/pages/building-your-application/configuring/babel). All transformations that Next.js handles by default like styled-jsx and tree-shaking of `getStaticProps` / `getStaticPaths` / `getServerSideProps` have been ported to Rust.
When an application has a custom Babel configuration, Next.js will automatically opt-out of using SWC for compiling JavaScript/Typescript and will fall back to using Babel in the same way that it was used in Next.js 11.
Many of the integrations with external libraries that currently require custom Babel transformations will be ported to Rust-based SWC transforms in the near future. These include but are not limited to:
* Styled Components
* Emotion
* Relay
In order to prioritize transforms that will help you adopt SWC, please provide your `.babelrc` on [this feedback thread](https://github.com/vercel/next.js/discussions/30174).
#### [SWC replacing Terser for minification](#swc-replacing-terser-for-minification)
You can opt-in to replacing Terser with SWC for minifying JavaScript up to 7x faster using a flag in `next.config.js`:
next.config.js
module.exports = {
swcMinify: true,
}
Minification using SWC is an opt-in flag to ensure it can be tested against more real-world Next.js applications before it becomes the default in Next.js 12.1. If you have feedback about minification, please leave it on [this feedback thread](https://github.com/vercel/next.js/discussions/30237).
#### [Improvements to styled-jsx CSS parsing](#improvements-to-styled-jsx-css-parsing)
On top of the Rust-based compiler we've implemented a new CSS parser based on the one used for the styled-jsx Babel transform. This new parser has improved handling of CSS and now errors when invalid CSS is used that would previously slip through and cause unexpected behavior.
Because of this change invalid CSS will throw an error during development and `next build`. This change only affects styled-jsx usage.
#### [`next/image` changed wrapping element](#nextimage-changed-wrapping-element)
`next/image` now renders the `<img>` inside a `<span>` instead of `<div>`.
If your application has specific CSS targeting span such as `.container span`, upgrading to Next.js 12 might incorrectly match the wrapping element inside the `<Image>` component. You can avoid this by restricting the selector to a specific class such as `.container span.item` and updating the relevant component with that className, such as `<span className="item" />`.
If your application has specific CSS targeting the `next/image` `<div>` tag, for example `.container div`, it may not match anymore. You can update the selector `.container span`, or preferably, add a new `<div className="wrapper">` wrapping the `<Image>` component and target that instead such as `.container .wrapper`.
The `className` prop is unchanged and will still be passed to the underlying `<img>` element.
See the [documentation](/docs/pages/building-your-application/optimizing/images#styling) for more info.
#### [HMR connection now uses a WebSocket](#hmr-connection-now-uses-a-websocket)
Previously, Next.js used a [server-sent events](https://developer.mozilla.org/docs/Web/API/Server-sent_events) connection to receive HMR events. Next.js 12 now uses a WebSocket connection.
In some cases when proxying requests to the Next.js dev server, you will need to ensure the upgrade request is handled correctly. For example, in `nginx` you would need to add the following configuration:
location /_next/webpack-hmr {
proxy_pass http://localhost:3000/_next/webpack-hmr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
If you are using Apache (2.x), you can add the following configuration to enable web sockets to the server. Review the port, host name and server names.
<VirtualHost *:443>
# ServerName yourwebsite.local
ServerName "${WEBSITE_SERVER_NAME}"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
# Next.js 12 uses websocket
<Location /_next/webpack-hmr>
RewriteEngine On
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) ws://localhost:3000/_next/webpack-hmr/$1 [P,L]
ProxyPass ws://localhost:3000/_next/webpack-hmr retry=0 timeout=30
ProxyPassReverse ws://localhost:3000/_next/webpack-hmr
</Location>
</VirtualHost>
For custom servers, such as `express`, you may need to use `app.all` to ensure the request is passed correctly, for example:
app.all('/_next/webpack-hmr', (req, res) => {
nextjsRequestHandler(req, res)
})
#### [Webpack 4 support has been removed](#webpack-4-support-has-been-removed)
If you are already using webpack 5 you can skip this section.
Next.js has adopted webpack 5 as the default for compilation in Next.js 11. As communicated in the [webpack 5 upgrading documentation](/docs/messages/webpack5) Next.js 12 removes support for webpack 4.
If your application is still using webpack 4 using the opt-out flag, you will now see an error linking to the [webpack 5 upgrading documentation](/docs/messages/webpack5).
#### [`target` option deprecated](#target-option-deprecated)
If you do not have `target` in `next.config.js` you can skip this section.
The target option has been deprecated in favor of built-in support for tracing what dependencies are needed to run a page.
During `next build`, Next.js will automatically trace each page and its dependencies to determine all of the files that are needed for deploying a production version of your application.
If you are currently using the `target` option set to `serverless`, please read the [documentation on how to leverage the new output](/docs/pages/api-reference/next-config-js/output).
[Previous
Version 13
](/docs/pages/building-your-application/upgrading/version-13)
[Next
Version 11
](/docs/pages/building-your-application/upgrading/version-11)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"c7b02de60ede7a96ed9c18d20e3e7c3d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/from-create-react-app | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [
Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Why Switch?](#why-switch)
* [Slow initial page loading time](#slow-initial-page-loading-time)
* [No automatic code splitting](#no-automatic-code-splitting)
* [Network waterfalls](#network-waterfalls)
* [Fast and intentional loading states](#fast-and-intentional-loading-states)
* [Choose the data fetching strategy](#choose-the-data-fetching-strategy)
* [Middleware](#middleware)
* [Built-in Optimizations](#built-in-optimizations)
* [Migration Steps](#migration-steps)
* [Step 1: Install the Next.js Dependency](#step-1-install-the-nextjs-dependency)
* [Step 2: Create the Next.js Configuration File](#step-2-create-the-nextjs-configuration-file)
* [Step 3: Update TypeScript Configuration](#step-3-update-typescript-configuration)
* [Step 4: Create the Root Layout](#step-4-create-the-root-layout)
* [Step 5: Metadata](#step-5-metadata)
* [Step 6: Styles](#step-6-styles)
* [Step 7: Create the Entrypoint Page](#step-7-create-the-entrypoint-page)
* [Step 8: Update Static Image Imports](#step-8-update-static-image-imports)
* [Step 9: Migrate the Environment Variables](#step-9-migrate-the-environment-variables)
* [Step 10: Update Scripts in package.json](#step-10-update-scripts-in-packagejson)
* [Step 11: Clean Up](#step-11-clean-up)
* [Bundler Compatibility](#bundler-compatibility)
* [Next Steps](#next-steps)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/04-from-create-react-app.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Migrating from Create React App
Migrating from Create React App
===============================
This guide will help you migrate an existing Create React App site to Next.js.
[Why Switch?](#why-switch)
--------------------------
There are several reasons why you might want to switch from Create React App to Next.js:
### [Slow initial page loading time](#slow-initial-page-loading-time)
Create React App uses purely client-side React. Client-side only applications, also known as single-page applications (SPAs), often experience slow initial page loading time. This happens due to a couple of reasons:
1. The browser needs to wait for the React code and your entire application bundle to download and run before your code is able to send requests to load data.
2. Your application code grows with every new feature and dependency you add.
### [No automatic code splitting](#no-automatic-code-splitting)
The previous issue of slow loading times can be somewhat managed with code splitting. However, if you try to do code splitting manually, you'll often make performance worse. It's easy to inadvertently introduce network waterfalls when code-splitting manually. Next.js provides automatic code splitting built into its router.
### [Network waterfalls](#network-waterfalls)
A common cause of poor performance occurs when applications make sequential client-server requests to fetch data. One common pattern for data fetching in an SPA is to initially render a placeholder, and then fetch data after the component has mounted. Unfortunately, this means that a child component that fetches data can't start fetching until the parent component has finished loading its own data.
While fetching data on the client is supported with Next.js, it also gives you the option to shift data fetching to the server, which can eliminate client-server waterfalls.
### [Fast and intentional loading states](#fast-and-intentional-loading-states)
With built-in support for [streaming through React Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense), you can be more intentional about which parts of your UI you want to load first and in what order without introducing network waterfalls.
This enables you to build pages that are faster to load and eliminate [layout shifts](https://vercel.com/blog/how-core-web-vitals-affect-seo).
### [Choose the data fetching strategy](#choose-the-data-fetching-strategy)
Depending on your needs, Next.js allows you to choose your data fetching strategy on a page and component basis. You can decide to fetch at build time, at request time on the server, or on the client. For example, you can fetch data from your CMS and render your blog posts at build time, which can then be efficiently cached on a CDN.
### [Middleware](#middleware)
[Next.js Middleware](/docs/app/building-your-application/routing/middleware) allows you to run code on the server before a request is completed. This is especially useful to avoid having a flash of unauthenticated content when the user visits an authenticated-only page by redirecting the user to a login page. The middleware is also useful for experimentation and [internationalization](/docs/app/building-your-application/routing/internationalization).
### [Built-in Optimizations](#built-in-optimizations)
[Images](/docs/app/building-your-application/optimizing/images), [fonts](/docs/app/building-your-application/optimizing/fonts), and [third-party scripts](/docs/app/building-your-application/optimizing/scripts) often have significant impact on an application's performance. Next.js comes with built-in components that automatically optimize those for you.
[Migration Steps](#migration-steps)
-----------------------------------
Our goal with this migration is to get a working Next.js application as quickly as possible, so that you can then adopt Next.js features incrementally. To begin with, we'll keep it as a purely client-side application (SPA) without migrating your existing router. This helps minimize the chances of encountering issues during the migration process and reduces merge conflicts.
### [Step 1: Install the Next.js Dependency](#step-1-install-the-nextjs-dependency)
The first thing you need to do is to install `next` as a dependency:
Terminal
npm install next@latest
### [Step 2: Create the Next.js Configuration File](#step-2-create-the-nextjs-configuration-file)
Create a `next.config.mjs` at the root of your project. This file will hold your [Next.js configuration options](/docs/app/api-reference/next-config-js).
next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // Outputs a Single-Page Application (SPA).
distDir: './dist', // Changes the build output directory to `./dist/`.
}
export default nextConfig
### [Step 3: Update TypeScript Configuration](#step-3-update-typescript-configuration)
If you're using TypeScript, you need to update your `tsconfig.json` file with the following changes to make it compatible with Next.js:
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"./dist/types/**/*.ts"
],
"exclude": ["node_modules"]
}
You can find more information about configuring TypeScript on the [Next.js docs](/docs/app/building-your-application/configuring/typescript#typescript-plugin).
### [Step 4: Create the Root Layout](#step-4-create-the-root-layout)
A Next.js [App Router](/docs/app) application must include a [root layout](/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) file, which is a [React Server Component](/docs/app/building-your-application/rendering/server-components) that will wrap all pages in your application. This file is defined at the top level of the `app` directory.
The closest equivalent to the root layout file in a CRA application is the `index.html` file, which contains your `<html>`, `<head>`, and `<body>` tags.
In this step, you'll convert your `index.html` file into a root layout file:
1. Create a new `app` directory in your `src` directory.
2. Create a new `layout.tsx` file inside that `app` directory:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return null
}
> **Good to know**: `.js`, `.jsx`, or `.tsx` extensions can be used for Layout files.
Copy the content of your `index.html` file into the previously created `<RootLayout>` component while replacing the `body.div#root` and `body.script` tags with `<div id="root">{children}</div>`:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>React App</title>
<meta name="description" content="Web site created..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
> **Good to know**: We'll ignore the [manifest file](/docs/app/api-reference/file-conventions/metadata), additional iconography other than the favicon, and [testing configuration](/docs/app/building-your-application/testing), but if these are requirements, Next.js also supports these options.
### [Step 5: Metadata](#step-5-metadata)
Next.js already includes by default the [meta charset](https://developer.mozilla.org/docs/Web/HTML/Element/meta#charset) and [meta viewport](https://developer.mozilla.org/docs/Web/HTML/Viewport_meta_tag) tags, so you can safely remove those from your `<head>`:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<title>React App</title>
<meta name="description" content="Web site created..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
Any [metadata files](/docs/app/building-your-application/optimizing/metadata#file-based-metadata) such as `favicon.ico`, `icon.png`, `robots.txt` are automatically added to the application `<head>` tag as long as you have them placed into the top level of the `app` directory. After moving [all supported files](/docs/app/building-your-application/optimizing/metadata#file-based-metadata) into the `app` directory you can safely delete their `<link>` tags:
app/layout.tsx
TypeScript
JavaScriptTypeScript
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<title>React App</title>
<meta name="description" content="Web site created..." />
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
Finally, Next.js can manage your last `<head>` tags with the [Metadata API](/docs/app/building-your-application/optimizing/metadata). Move your final metadata info into an exported [`metadata` object](/docs/app/api-reference/functions/generate-metadata#metadata-object):
app/layout.tsx
TypeScript
JavaScriptTypeScript
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'React App',
description: 'Web site created with Next.js.',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<div id="root">{children}</div>
</body>
</html>
)
}
With the above changes, you shifted from declaring everything in your `index.html` to using Next.js' convention-based approach built into the framework ([Metadata API](/docs/app/building-your-application/optimizing/metadata)). This approach enables you to more easily improve your SEO and web shareability of your pages.
### [Step 6: Styles](#step-6-styles)
Like Create React App, Next.js has built-in support for [CSS Modules](/docs/app/building-your-application/styling/css-modules).
If you're using a global CSS file, import it into your `app/layout.tsx` file:
app/layout.tsx
TypeScript
JavaScriptTypeScript
import '../index.css'
// ...
If you're using Tailwind, you'll need to install `postcss` and `autoprefixer`:
Terminal
npm install postcss autoprefixer
Then, create a `postcss.config.js` file at the root of your project:
postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
### [Step 7: Create the Entrypoint Page](#step-7-create-the-entrypoint-page)
On Next.js you declare an entrypoint for your application by creating a `page.tsx` file. The closest equivalent of this file on CRA is your `src/index.tsx` file. In this step, you’ll set up the entry point of your application.
**Create a `[[...slug]]` directory in your `app` directory.**
Since this guide is aiming to first set up our Next.js as an SPA (Single Page Application), you need your page entry point to catch all possible routes of your application. For that, create a new `[[...slug]]` directory in your `app` directory.
This directory is what is called an [optional catch-all route segment](/docs/app/building-your-application/routing/dynamic-routes#optional-catch-all-segments). Next.js uses a file-system based router where [directories are used to define routes](/docs/app/building-your-application/routing/defining-routes#creating-routes). This special directory will make sure that all routes of your application will be directed to its containing `page.tsx` file.
**Create a new `page.tsx` file inside the `app/[[...slug]]` directory with the following content:**
app/\[\[...slug\]\]/page.tsx
TypeScript
JavaScriptTypeScript
import '../../index.css'
export function generateStaticParams() {
return [{ slug: [''] }]
}
export default function Page() {
return '...' // We'll update this
}
This file is a [Server Component](/docs/app/building-your-application/rendering/server-components). When you run `next build`, the file is prerendered into a static asset. It does _not_ require any dynamic code.
This file imports our global CSS and tells [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) we are only going to generate one route, the index route at `/`.
Now, let's move the rest of our CRA application which will run client-only.
app/\[\[...slug\]\]/client.tsx
TypeScript
JavaScriptTypeScript
'use client'
import React from 'react'
import dynamic from 'next/dynamic'
const App = dynamic(() => import('../../App'), { ssr: false })
export function ClientOnly() {
return <App />
}
This file is a [Client Component](/docs/app/building-your-application/rendering/client-components), defined by the `'use client'` directive. Client Components are still [prerendered to HTML](/docs/app/building-your-application/rendering/client-components#how-are-client-components-rendered) on the server before being sent to the client.
Since we want a client-only application to start, we can configure Next.js to disable prerendering from the `App` component down.
const App = dynamic(() => import('../../App'), { ssr: false })
Now, update your entrypoint page to use the new component:
app/\[\[...slug\]\]/page.tsx
TypeScript
JavaScriptTypeScript
import '../../index.css'
import { ClientOnly } from './client'
export function generateStaticParams() {
return [{ slug: [''] }]
}
export default function Page() {
return <ClientOnly />
}
### [Step 8: Update Static Image Imports](#step-8-update-static-image-imports)
Next.js handles static image imports slightly different from CRA. With CRA, importing an image file will return its public URL as a string:
App.tsx
import image from './img.png'
export default function App() {
return <img src={image} />
}
With Next.js, static image imports return an object. The object can then be used directly with the Next.js [`<Image>` component](/docs/app/api-reference/components/image), or you can use the object's `src` property with your existing `<img>` tag.
The `<Image>` component has the added benefits of [automatic image optimization](/docs/app/building-your-application/optimizing/images). The `<Image>` component automatically sets the `width` and `height` attributes of the resulting `<img>` based on the image's dimensions. This prevents layout shifts when the image loads. However, this can cause issues if your app contains images with only one of their dimensions being styled without the other styled to `auto`. When not styled to `auto`, the dimension will default to the `<img>` dimension attribute's value, which can cause the image to appear distorted.
Keeping the `<img>` tag will reduce the amount of changes in your application and prevent the above issues. You can then optionally later migrate to the `<Image>` component to take advantage of optimizing images by [configuring a loader](/docs/app/building-your-application/optimizing/images#loaders), or moving to the default Next.js server which has automatic image optimization.
**Convert absolute import paths for images imported from `/public` into relative imports:**
// Before
import logo from '/logo.png'
// After
import logo from '../public/logo.png'
**Pass the image `src` property instead of the whole image object to your `<img>` tag:**
// Before
<img src={logo} />
// After
<img src={logo.src} />
Alternatively, you can reference the public URL for the image asset based on the filename. For example, `public/logo.png` will serve the image at `/logo.png` for your application, which would be the `src` value.
> **Warning:** If you're using TypeScript, you might encounter type errors when accessing the `src` property. You can safely ignore those for now. They will be fixed by the end of this guide.
### [Step 9: Migrate the Environment Variables](#step-9-migrate-the-environment-variables)
Next.js has support for `.env` [environment variables](/docs/app/building-your-application/configuring/environment-variables) similar to CRA.
The main difference is the prefix used to expose environment variables on the client-side. Change all environment variables with the `REACT_APP_` prefix to `NEXT_PUBLIC_`.
### [Step 10: Update Scripts in `package.json`](#step-10-update-scripts-in-packagejson)
You should now be able to run your application to test if you successfully migrated to Next.js. But before that, you need to update your `scripts` in your `package.json` with Next.js related commands, and add `.next`, `next-env.d.ts`, and `dist` to your `.gitignore` file:
package.json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
.gitignore
# ...
.next
next-env.d.ts
dist
Now run `npm run dev`, and open [`http://localhost:3000`](http://localhost:3000). You should see your application now running on Next.js.
### [Step 11: Clean Up](#step-11-clean-up)
You can now clean up your codebase from Create React App related artifacts:
* Delete `src/index.tsx`
* Delete `public/index.html`
* Delete `reportWebVitals` setup
* Uninstall CRA dependencies (`react-scripts`)
[Bundler Compatibility](#bundler-compatibility)
-----------------------------------------------
Create React App and Next.js both default to using webpack for bundling.
When migrating your CRA application to Next.js, you might have a custom webpack configuration you're looking to migrate. Next.js supports providing a [custom webpack configuration](/docs/app/api-reference/next-config-js/webpack).
Further, Next.js has support for [Turbopack](/docs/app/api-reference/next-config-js/turbo) through `next dev --turbo` to improve your local dev performance. Turbopack supports some [webpack loaders](/docs/app/api-reference/next-config-js/turbo) as well for compatibility and incremental adoption.
[Next Steps](#next-steps)
-------------------------
If everything went according to plan, you now have a functioning Next.js application running as a single-page application. However, you aren't yet taking advantage of most of Next.js' benefits, but you can now start making incremental changes to reap all the benefits. Here's what you might want to do next:
* Migrate from React Router to the [Next.js App Router](/docs/app/building-your-application/routing) to get:
* Automatic code splitting
* [Streaming Server-Rendering](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [React Server Components](/docs/app/building-your-application/rendering/server-components)
* [Optimize images with the `<Image>` component](/docs/app/building-your-application/optimizing/images)
* [Optimize fonts with `next/font`](/docs/app/building-your-application/optimizing/fonts)
* [Optimize third-party scripts with the `<Script>` component](/docs/app/building-your-application/optimizing/scripts)
* [Update your ESLint configuration to support Next.js rules](/docs/app/building-your-application/configuring/eslint)
> **Good to know:** Using a static export [does not currently support](https://github.com/vercel/next.js/issues/54393) using the `useParams` hook.
[Previous
Migrating from Vite
](/docs/pages/building-your-application/upgrading/from-vite)
[Next
Version 14
](/docs/pages/building-your-application/upgrading/version-14)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"88d3c49f8c6185cc0f3fbb8b86cc85ea\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/font | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [
Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Font Function Arguments](#font-function-arguments)
* [src](#src)
* [weight](#weight)
* [style](#style)
* [subsets](#subsets)
* [axes](#axes)
* [display](#display)
* [preload](#preload)
* [fallback](#fallback)
* [adjustFontFallback](#adjustfontfallback)
* [variable](#variable)
* [declarations](#declarations)
* [Applying Styles](#applying-styles)
* [className](#classname)
* [style](#style-1)
* [CSS Variables](#css-variables)
* [Using a font definitions file](#using-a-font-definitions-file)
* [Version Changes](#version-changes)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/font.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)Font
Font Module
===========
This API reference will help you understand how to use [`next/font/google`](/docs/app/building-your-application/optimizing/fonts#google-fonts) and [`next/font/local`](/docs/app/building-your-application/optimizing/fonts#local-fonts). For features and usage, please see the [Optimizing Fonts](/docs/app/building-your-application/optimizing/fonts) page.
### [Font Function Arguments](#font-function-arguments)
For usage, review [Google Fonts](/docs/app/building-your-application/optimizing/fonts#google-fonts) and [Local Fonts](/docs/app/building-your-application/optimizing/fonts#local-fonts).
Key
`font/google`
`font/local`
Type
Required
[`src`](#src)
String or Array of Objects
Yes
[`weight`](#weight)
String or Array
Required/Optional
[`style`](#style)
String or Array
\-
[`subsets`](#subsets)
Array of Strings
\-
[`axes`](#axes)
Array of Strings
\-
[`display`](#display)
String
\-
[`preload`](#preload)
Boolean
\-
[`fallback`](#fallback)
Array of Strings
\-
[`adjustFontFallback`](#adjustfontfallback)
Boolean or String
\-
[`variable`](#variable)
String
\-
[`declarations`](#declarations)
Array of Objects
\-
### [`src`](#src)
The path of the font file as a string or an array of objects (with type `Array<{path: string, weight?: string, style?: string}>`) relative to the directory where the font loader function is called.
Used in `next/font/local`
* Required
Examples:
* `src:'./fonts/my-font.woff2'` where `my-font.woff2` is placed in a directory named `fonts` inside the `app` directory
* `src:[{path: './inter/Inter-Thin.ttf', weight: '100',},{path: './inter/Inter-Regular.ttf',weight: '400',},{path: './inter/Inter-Bold-Italic.ttf', weight: '700',style: 'italic',},]`
* if the font loader function is called in `app/page.tsx` using `src:'../styles/fonts/my-font.ttf'`, then `my-font.ttf` is placed in `styles/fonts` at the root of the project
### [`weight`](#weight)
The font [`weight`](https://fonts.google.com/knowledge/glossary/weight) with the following possibilities:
* A string with possible values of the weights available for the specific font or a range of values if it's a [variable](https://fonts.google.com/variablefonts) font
* An array of weight values if the font is not a [variable google font](https://fonts.google.com/variablefonts). It applies to `next/font/google` only.
Used in `next/font/google` and `next/font/local`
* Required if the font being used is **not** [variable](https://fonts.google.com/variablefonts)
Examples:
* `weight: '400'`: A string for a single weight value - for the font [`Inter`](https://fonts.google.com/specimen/Inter?query=inter), the possible values are `'100'`, `'200'`, `'300'`, `'400'`, `'500'`, `'600'`, `'700'`, `'800'`, `'900'` or `'variable'` where `'variable'` is the default)
* `weight: '100 900'`: A string for the range between `100` and `900` for a variable font
* `weight: ['100','400','900']`: An array of 3 possible values for a non variable font
### [`style`](#style)
The font [`style`](https://developer.mozilla.org/docs/Web/CSS/font-style) with the following possibilities:
* A string [value](https://developer.mozilla.org/docs/Web/CSS/font-style#values) with default value of `'normal'`
* An array of style values if the font is not a [variable google font](https://fonts.google.com/variablefonts). It applies to `next/font/google` only.
Used in `next/font/google` and `next/font/local`
* Optional
Examples:
* `style: 'italic'`: A string - it can be `normal` or `italic` for `next/font/google`
* `style: 'oblique'`: A string - it can take any value for `next/font/local` but is expected to come from [standard font styles](https://developer.mozilla.org/docs/Web/CSS/font-style)
* `style: ['italic','normal']`: An array of 2 values for `next/font/google` - the values are from `normal` and `italic`
### [`subsets`](#subsets)
The font [`subsets`](https://fonts.google.com/knowledge/glossary/subsetting) defined by an array of string values with the names of each subset you would like to be [preloaded](/docs/app/building-your-application/optimizing/fonts#specifying-a-subset). Fonts specified via `subsets` will have a link preload tag injected into the head when the [`preload`](#preload) option is true, which is the default.
Used in `next/font/google`
* Optional
Examples:
* `subsets: ['latin']`: An array with the subset `latin`
You can find a list of all subsets on the Google Fonts page for your font.
### [`axes`](#axes)
Some variable fonts have extra `axes` that can be included. By default, only the font weight is included to keep the file size down. The possible values of `axes` depend on the specific font.
Used in `next/font/google`
* Optional
Examples:
* `axes: ['slnt']`: An array with value `slnt` for the `Inter` variable font which has `slnt` as additional `axes` as shown [here](https://fonts.google.com/variablefonts?vfquery=inter#font-families). You can find the possible `axes` values for your font by using the filter on the [Google variable fonts page](https://fonts.google.com/variablefonts#font-families) and looking for axes other than `wght`
### [`display`](#display)
The font [`display`](https://developer.mozilla.org/docs/Web/CSS/@font-face/font-display) with possible string [values](https://developer.mozilla.org/docs/Web/CSS/@font-face/font-display#values) of `'auto'`, `'block'`, `'swap'`, `'fallback'` or `'optional'` with default value of `'swap'`.
Used in `next/font/google` and `next/font/local`
* Optional
Examples:
* `display: 'optional'`: A string assigned to the `optional` value
### [`preload`](#preload)
A boolean value that specifies whether the font should be [preloaded](/docs/app/building-your-application/optimizing/fonts#preloading) or not. The default is `true`.
Used in `next/font/google` and `next/font/local`
* Optional
Examples:
* `preload: false`
### [`fallback`](#fallback)
The fallback font to use if the font cannot be loaded. An array of strings of fallback fonts with no default.
* Optional
Used in `next/font/google` and `next/font/local`
Examples:
* `fallback: ['system-ui', 'arial']`: An array setting the fallback fonts to `system-ui` or `arial`
### [`adjustFontFallback`](#adjustfontfallback)
* For `next/font/google`: A boolean value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The default is `true`.
* For `next/font/local`: A string or boolean `false` value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The possible values are `'Arial'`, `'Times New Roman'` or `false`. The default is `'Arial'`.
Used in `next/font/google` and `next/font/local`
* Optional
Examples:
* `adjustFontFallback: false`: for `next/font/google`
* `adjustFontFallback: 'Times New Roman'`: for `next/font/local`
### [`variable`](#variable)
A string value to define the CSS variable name to be used if the style is applied with the [CSS variable method](#css-variables).
Used in `next/font/google` and `next/font/local`
* Optional
Examples:
* `variable: '--my-font'`: The CSS variable `--my-font` is declared
### [`declarations`](#declarations)
An array of font face [descriptor](https://developer.mozilla.org/docs/Web/CSS/@font-face#descriptors) key-value pairs that define the generated `@font-face` further.
Used in `next/font/local`
* Optional
Examples:
* `declarations: [{ prop: 'ascent-override', value: '90%' }]`
[Applying Styles](#applying-styles)
-----------------------------------
You can apply the font styles in three ways:
* [`className`](#classname)
* [`style`](#style-1)
* [CSS Variables](#css-variables)
### [`className`](#classname)
Returns a read-only CSS `className` for the loaded font to be passed to an HTML element.
<p className={inter.className}>Hello, Next.js!</p>
### [`style`](#style-1)
Returns a read-only CSS `style` object for the loaded font to be passed to an HTML element, including `style.fontFamily` to access the font family name and fallback fonts.
<p style={inter.style}>Hello World</p>
### [CSS Variables](#css-variables)
If you would like to set your styles in an external style sheet and specify additional options there, use the CSS variable method.
In addition to importing the font, also import the CSS file where the CSS variable is defined and set the variable option of the font loader object as follows:
app/page.tsx
TypeScript
JavaScriptTypeScript
import { Inter } from 'next/font/google'
import styles from '../styles/component.module.css'
const inter = Inter({
variable: '--font-inter',
})
To use the font, set the `className` of the parent container of the text you would like to style to the font loader's `variable` value and the `className` of the text to the `styles` property from the external CSS file.
app/page.tsx
TypeScript
JavaScriptTypeScript
<main className={inter.variable}>
<p className={styles.text}>Hello World</p>
</main>
Define the `text` selector class in the `component.module.css` CSS file as follows:
styles/component.module.css
.text {
font-family: var(--font-inter);
font-weight: 200;
font-style: italic;
}
In the example above, the text `Hello World` is styled using the `Inter` font and the generated font fallback with `font-weight: 200` and `font-style: italic`.
[Using a font definitions file](#using-a-font-definitions-file)
---------------------------------------------------------------
Every time you call the `localFont` or Google font function, that font will be hosted as one instance in your application. Therefore, if you need to use the same font in multiple places, you should load it in one place and import the related font object where you need it. This is done using a font definitions file.
For example, create a `fonts.ts` file in a `styles` folder at the root of your app directory.
Then, specify your font definitions as follows:
styles/fonts.ts
TypeScript
JavaScriptTypeScript
import { Inter, Lora, Source_Sans_3 } from 'next/font/google'
import localFont from 'next/font/local'
// define your variable fonts
const inter = Inter()
const lora = Lora()
// define 2 weights of a non-variable font
const sourceCodePro400 = Source_Sans_3({ weight: '400' })
const sourceCodePro700 = Source_Sans_3({ weight: '700' })
// define a custom local font where GreatVibes-Regular.ttf is stored in the styles folder
const greatVibes = localFont({ src: './GreatVibes-Regular.ttf' })
export { inter, lora, sourceCodePro400, sourceCodePro700, greatVibes }
You can now use these definitions in your code as follows:
app/page.tsx
TypeScript
JavaScriptTypeScript
import { inter, lora, sourceCodePro700, greatVibes } from '../styles/fonts'
export default function Page() {
return (
<div>
<p className={inter.className}>Hello world using Inter font</p>
<p style={lora.style}>Hello world using Lora font</p>
<p className={sourceCodePro700.className}>
Hello world using Source_Sans_3 font with weight 700
</p>
<p className={greatVibes.className}>My title in Great Vibes font</p>
</div>
)
}
To make it easier to access the font definitions in your code, you can define a path alias in your `tsconfig.json` or `jsconfig.json` files as follows:
tsconfig.json
{
"compilerOptions": {
"paths": {
"@/fonts": ["./styles/fonts"]
}
}
}
You can now import any font definition as follows:
app/about/page.tsx
TypeScript
JavaScriptTypeScript
import { greatVibes, sourceCodePro400 } from '@/fonts'
[Version Changes](#version-changes)
-----------------------------------
Version
Changes
`v13.2.0`
`@next/font` renamed to `next/font`. Installation no longer required.
`v13.0.0`
`@next/font` was added.
[Previous
Components
](/docs/pages/api-reference/components)
[Next
<Head>
](/docs/pages/api-reference/components/head)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"fcab0152a85751296b1b24bbfd916d16\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)Components
Components
==========
[
### Font
API Reference for the Font Module
](/docs/pages/api-reference/components/font)[
### <Head>
Add custom elements to the \`head\` of your page with the built-in Head component.
](/docs/pages/api-reference/components/head)[
### <Image>
Optimize Images in your Next.js Application using the built-in \`next/image\` Component.
](/docs/pages/api-reference/components/image)[
### <Image> (Legacy)
Backwards compatible Image Optimization with the Legacy Image component.
](/docs/pages/api-reference/components/image-legacy)[
### <Link>
API reference for the <Link> component.
](/docs/pages/api-reference/components/link)[
### <Script>
Optimize third-party scripts in your Next.js application using the built-in \`next/script\` Component.
](/docs/pages/api-reference/components/script)
[Previous
API Reference
](/docs/pages/api-reference)
[Next
Font
](/docs/pages/api-reference/components/font)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f47557393cfb6b4c7f7c3f944ad0a764\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-10 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [
Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/09-version-10.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 10
Version 10
==========
There were no breaking changes between versions 9 and 10.
To upgrade to version 10, run the following command:
Terminal
npm i next@10
Terminal
yarn add next@10
Terminal
pnpm up next@10
Terminal
bun add next@10
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their corresponding versions.
[Previous
Version 11
](/docs/pages/building-your-application/upgrading/version-11)
[Next
Version 9
](/docs/pages/building-your-application/upgrading/version-9)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"b944a7da5c329a054499e24513e7f1eb\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-11 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [
Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Webpack 5](#webpack-5)
* [Cleaning the distDir is now a default](#cleaning-the-distdir-is-now-a-default)
* [PORT is now supported for next dev and next start](#port-is-now-supported-for-next-dev-and-next-start)
* [next.config.js customization to import images](#nextconfigjs-customization-to-import-images)
* [Remove super.componentDidCatch() from pages/\_app.js](#remove-supercomponentdidcatch-from-pages_appjs)
* [Remove Container from pages/\_app.js](#remove-container-from-pages_appjs)
* [Remove props.url usage from page components](#remove-propsurl-usage-from-page-components)
* [Remove unsized property on next/image](#remove-unsized-property-on-nextimage)
* [Remove modules property on next/dynamic](#remove-modules-property-on-nextdynamic)
* [Remove Head.rewind](#remove-headrewind)
* [Moment.js locales excluded by default](#momentjs-locales-excluded-by-default)
* [Update usage of router.events](#update-usage-of-routerevents)
* [React 16 to 17](#react-16-to-17)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/08-version-11.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 11
Version 11
==========
To upgrade to version 11, run the following command:
Terminal
npm i next@11 react@17 react-dom@17
Terminal
yarn add next@11 react@17 react-dom@17
Terminal
pnpm up next@11 react@17 react-dom@17
Terminal
bun add next@11 react@17 react-dom@17
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their corresponding versions.
### [Webpack 5](#webpack-5)
Webpack 5 is now the default for all Next.js applications. If you did not have a custom webpack configuration, your application is already using webpack 5. If you do have a custom webpack configuration, you can refer to the [Next.js webpack 5 documentation](/docs/messages/webpack5) for upgrade guidance.
### [Cleaning the `distDir` is now a default](#cleaning-the-distdir-is-now-a-default)
The build output directory (defaults to `.next`) is now cleared by default except for the Next.js caches. You can refer to [the cleaning `distDir` RFC](https://github.com/vercel/next.js/discussions/6009) for more information.
If your application was relying on this behavior previously you can disable the new default behavior by adding the `cleanDistDir: false` flag in `next.config.js`.
### [`PORT` is now supported for `next dev` and `next start`](#port-is-now-supported-for-next-dev-and-next-start)
Next.js 11 supports the `PORT` environment variable to set the port the application runs on. Using `-p`/`--port` is still recommended but if you were prohibited from using `-p` in any way you can now use `PORT` as an alternative:
Example:
PORT=4000 next start
### [`next.config.js` customization to import images](#nextconfigjs-customization-to-import-images)
Next.js 11 supports static image imports with `next/image`. This new feature relies on being able to process image imports. If you previously added the `next-images` or `next-optimized-images` packages you can either move to the new built-in support using `next/image` or disable the feature:
next.config.js
module.exports = {
images: {
disableStaticImages: true,
},
}
### [Remove `super.componentDidCatch()` from `pages/_app.js`](#remove-supercomponentdidcatch-from-pages_appjs)
The `next/app` component's `componentDidCatch` was deprecated in Next.js 9 as it's no longer needed and has since been a no-op. In Next.js 11, it was removed.
If your `pages/_app.js` has a custom `componentDidCatch` method you can remove `super.componentDidCatch` as it is no longer needed.
### [Remove `Container` from `pages/_app.js`](#remove-container-from-pages_appjs)
This export was deprecated in Next.js 9 as it's no longer needed and has since been a no-op with a warning during development. In Next.js 11 it was removed.
If your `pages/_app.js` imports `Container` from `next/app` you can remove `Container` as it was removed. Learn more in [the documentation](/docs/messages/app-container-deprecated).
### [Remove `props.url` usage from page components](#remove-propsurl-usage-from-page-components)
This property was deprecated in Next.js 4 and has since shown a warning during development. With the introduction of `getStaticProps` / `getServerSideProps` these methods already disallowed the usage of `props.url`. In Next.js 11, it was removed completely.
You can learn more in [the documentation](/docs/messages/url-deprecated).
### [Remove `unsized` property on `next/image`](#remove-unsized-property-on-nextimage)
The `unsized` property on `next/image` was deprecated in Next.js 10.0.1. You can use `layout="fill"` instead. In Next.js 11 `unsized` was removed.
### [Remove `modules` property on `next/dynamic`](#remove-modules-property-on-nextdynamic)
The `modules` and `render` option for `next/dynamic` were deprecated in Next.js 9.5. This was done in order to make the `next/dynamic` API closer to `React.lazy`. In Next.js 11, the `modules` and `render` options were removed.
This option hasn't been mentioned in the documentation since Next.js 8 so it's less likely that your application is using it.
If your application does use `modules` and `render` you can refer to [the documentation](/docs/messages/next-dynamic-modules).
### [Remove `Head.rewind`](#remove-headrewind)
`Head.rewind` has been a no-op since Next.js 9.5, in Next.js 11 it was removed. You can safely remove your usage of `Head.rewind`.
### [Moment.js locales excluded by default](#momentjs-locales-excluded-by-default)
Moment.js includes translations for a lot of locales by default. Next.js now automatically excludes these locales by default to optimize bundle size for applications using Moment.js.
To load a specific locale use this snippet:
import moment from 'moment'
import 'moment/locale/ja'
moment.locale('ja')
You can opt-out of this new default by adding `excludeDefaultMomentLocales: false` to `next.config.js` if you do not want the new behavior, do note it's highly recommended to not disable this new optimization as it significantly reduces the size of Moment.js.
### [Update usage of `router.events`](#update-usage-of-routerevents)
In case you're accessing `router.events` during rendering, in Next.js 11 `router.events` is no longer provided during pre-rendering. Ensure you're accessing `router.events` in `useEffect`:
useEffect(() => {
const handleRouteChange = (url, { shallow }) => {
console.log(
`App is changing to ${url} ${
shallow ? 'with' : 'without'
} shallow routing`
)
}
router.events.on('routeChangeStart', handleRouteChange)
// If the component is unmounted, unsubscribe
// from the event with the `off` method:
return () => {
router.events.off('routeChangeStart', handleRouteChange)
}
}, [router])
If your application uses `router.router.events` which was an internal property that was not public please make sure to use `router.events` as well.
[React 16 to 17](#react-16-to-17)
---------------------------------
React 17 introduced a new [JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) that brings a long-time Next.js feature to the wider React ecosystem: Not having to `import React from 'react'` when using JSX. When using React 17 Next.js will automatically use the new transform. This transform does not make the `React` variable global, which was an unintended side-effect of the previous Next.js implementation. A [codemod is available](/docs/pages/building-your-application/upgrading/codemods#add-missing-react-import) to automatically fix cases where you accidentally used `React` without importing it.
Most applications already use the latest version of React, with Next.js 11 the minimum React version has been updated to 17.0.2.
To upgrade you can run the following command:
npm install react@latest react-dom@latest
Or using `yarn`:
yarn add react@latest react-dom@latest
[Previous
Version 12
](/docs/pages/building-your-application/upgrading/version-12)
[Next
Version 10
](/docs/pages/building-your-application/upgrading/version-10)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"629891f3dd7a13a21febd8537a160280\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)API Reference
API Reference
=============
[
### Components
API Reference for Next.js built-in components in the Pages Router.
](/docs/pages/api-reference/components)[
### Functions
API Reference for Functions and Hooks in Pages Router.
](/docs/pages/api-reference/functions)[
### next.config.js Options
Learn about the options available in next.config.js for the Pages Router.
](/docs/pages/api-reference/next-config-js)[
### create-next-app
create-next-app
](/docs/pages/api-reference/create-next-app)[
### Next.js CLI
Next.js CLI
](/docs/pages/api-reference/next-cli)[
### Edge Runtime
API Reference for the Edge Runtime.
](/docs/pages/api-reference/edge)
[Previous
Version 9
](/docs/pages/building-your-application/upgrading/version-9)
[Next
Components
](/docs/pages/api-reference/components)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"fdbf07e2726d29a82df9d1021382c5d5\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/building-your-application/upgrading/version-9 | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [
Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Production Deployment on Vercel](#production-deployment-on-vercel)
* [Check your Custom App File (pages/\_app.js)](#check-your-custom-app-file-pages_appjs)
* [Breaking Changes](#breaking-changes)
* [@zeit/next-typescript is no longer necessary](#zeitnext-typescript-is-no-longer-necessary)
* [The config key is now an export on a page](#the-config-key-is-now-an-export-on-a-page)
* [next/dynamic no longer renders "loading..." by default while loading](#nextdynamic-no-longer-renders-loading-by-default-while-loading)
* [withAmp has been removed in favor of an exported configuration object](#withamp-has-been-removed-in-favor-of-an-exported-configuration-object)
* [next export no longer exports pages as index.html](#next-export-no-longer-exports-pages-as-indexhtml)
* [pages/api/ is treated differently](#pagesapi-is-treated-differently)
* [Deprecated Features](#deprecated-features)
* [next/dynamic has deprecated loading multiple modules at once](#nextdynamic-has-deprecated-loading-multiple-modules-at-once)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/01-building-your-application/10-upgrading/10-version-9.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/building-your-application)[Upgrading](/docs/pages/building-your-application/upgrading)Version 9
Upgrading to Version 9
======================
To upgrade to version 9, run the following command:
Terminal
npm i next@9
Terminal
yarn add next@9
Terminal
pnpm up next@9
Terminal
bun add next@9
> **Good to know:** If you are using TypeScript, ensure you also upgrade `@types/react` and `@types/react-dom` to their corresponding versions.
[Production Deployment on Vercel](#production-deployment-on-vercel)
-------------------------------------------------------------------
If you previously configured `routes` in your `vercel.json` file for dynamic routes, these rules can be removed when leveraging Next.js 9's new [Dynamic Routing feature](/docs/pages/building-your-application/routing/dynamic-routes).
Next.js 9's dynamic routes are **automatically configured on [Vercel](https://vercel.com/)** and do not require any `vercel.json` customization.
You can read more about [Dynamic Routing here](/docs/pages/building-your-application/routing/dynamic-routes).
[Check your Custom App File (`pages/_app.js`)](#check-your-custom-app-file-pages_appjs)
---------------------------------------------------------------------------------------
If you previously copied the [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) example, you may be able to remove your `getInitialProps`.
Removing `getInitialProps` from `pages/_app.js` (when possible) is important to leverage new Next.js features!
The following `getInitialProps` does nothing and may be removed:
class MyApp extends App {
// Remove me, I do nothing!
static async getInitialProps({ Component, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return { pageProps }
}
render() {
// ... etc
}
}
[Breaking Changes](#breaking-changes)
-------------------------------------
### [`@zeit/next-typescript` is no longer necessary](#zeitnext-typescript-is-no-longer-necessary)
Next.js will now ignore usage `@zeit/next-typescript` and warn you to remove it. Please remove this plugin from your `next.config.js`.
Remove references to `@zeit/next-typescript/babel` from your custom `.babelrc` (if present).
The usage of [`fork-ts-checker-webpack-plugin`](https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues) should also be removed from your `next.config.js`.
TypeScript Definitions are published with the `next` package, so you need to uninstall `@types/next` as they would conflict.
The following types are different:
> This list was created by the community to help you upgrade, if you find other differences please send a pull-request to this list to help other users.
From:
import { NextContext } from 'next'
import { NextAppContext, DefaultAppIProps } from 'next/app'
import { NextDocumentContext, DefaultDocumentIProps } from 'next/document'
to
import { NextPageContext } from 'next'
import { AppContext, AppInitialProps } from 'next/app'
import { DocumentContext, DocumentInitialProps } from 'next/document'
### [The `config` key is now an export on a page](#the-config-key-is-now-an-export-on-a-page)
You may no longer export a custom variable named `config` from a page (i.e. `export { config }` / `export const config ...`). This exported variable is now used to specify page-level Next.js configuration like Opt-in AMP and API Route features.
You must rename a non-Next.js-purposed `config` export to something different.
### [`next/dynamic` no longer renders "loading..." by default while loading](#nextdynamic-no-longer-renders-loading-by-default-while-loading)
Dynamic components will not render anything by default while loading. You can still customize this behavior by setting the `loading` property:
import dynamic from 'next/dynamic'
const DynamicComponentWithCustomLoading = dynamic(
() => import('../components/hello2'),
{
loading: () => <p>Loading</p>,
}
)
### [`withAmp` has been removed in favor of an exported configuration object](#withamp-has-been-removed-in-favor-of-an-exported-configuration-object)
Next.js now has the concept of page-level configuration, so the `withAmp` higher-order component has been removed for consistency.
This change can be **automatically migrated by running the following commands in the root of your Next.js project:**
Terminal
curl -L https://github.com/vercel/next-codemod/archive/master.tar.gz | tar -xz --strip=2 next-codemod-master/transforms/withamp-to-config.js npx jscodeshift -t ./withamp-to-config.js pages/**/*.js
To perform this migration by hand, or view what the codemod will produce, see below:
**Before**
import { withAmp } from 'next/amp'
function Home() {
return <h1>My AMP Page</h1>
}
export default withAmp(Home)
// or
export default withAmp(Home, { hybrid: true })
**After**
export default function Home() {
return <h1>My AMP Page</h1>
}
export const config = {
amp: true,
// or
amp: 'hybrid',
}
### [`next export` no longer exports pages as `index.html`](#next-export-no-longer-exports-pages-as-indexhtml)
Previously, exporting `pages/about.js` would result in `out/about/index.html`. This behavior has been changed to result in `out/about.html`.
You can revert to the previous behavior by creating a `next.config.js` with the following content:
next.config.js
module.exports = {
trailingSlash: true,
}
### [`pages/api/` is treated differently](#pagesapi-is-treated-differently)
Pages in `pages/api/` are now considered [API Routes](https://nextjs.org/blog/next-9#api-routes). Pages in this directory will no longer contain a client-side bundle.
[Deprecated Features](#deprecated-features)
-------------------------------------------
### [`next/dynamic` has deprecated loading multiple modules at once](#nextdynamic-has-deprecated-loading-multiple-modules-at-once)
The ability to load multiple modules at once has been deprecated in `next/dynamic` to be closer to React's implementation (`React.lazy` and `Suspense`).
Updating code that relies on this behavior is relatively straightforward! We've provided an example of a before/after to help you migrate your application:
**Before**
import dynamic from 'next/dynamic'
const HelloBundle = dynamic({
modules: () => {
const components = {
Hello1: () => import('../components/hello1').then((m) => m.default),
Hello2: () => import('../components/hello2').then((m) => m.default),
}
return components
},
render: (props, { Hello1, Hello2 }) => (
<div>
<h1>{props.title}</h1>
<Hello1 />
<Hello2 />
</div>
),
})
function DynamicBundle() {
return <HelloBundle title="Dynamic Bundle" />
}
export default DynamicBundle
**After**
import dynamic from 'next/dynamic'
const Hello1 = dynamic(() => import('../components/hello1'))
const Hello2 = dynamic(() => import('../components/hello2'))
function HelloBundle({ title }) {
return (
<div>
<h1>{title}</h1>
<Hello1 />
<Hello2 />
</div>
)
}
function DynamicBundle() {
return <HelloBundle title="Dynamic Bundle" />
}
export default DynamicBundle
[Previous
Version 10
](/docs/pages/building-your-application/upgrading/version-10)
[Next
API Reference
](/docs/pages/api-reference)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"1105530dac260b1824e27c85a1193b90\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/link | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [
<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Props](#props)
* [href (required)](#href-required)
* [replace](#replace)
* [scroll](#scroll)
* [prefetch](#prefetch)
* [Other Props](#other-props)
* [legacyBehavior](#legacybehavior)
* [passHref](#passhref)
* [scroll](#scroll-1)
* [shallow](#shallow)
* [locale](#locale)
* [Examples](#examples)
* [Linking to Dynamic Routes](#linking-to-dynamic-routes)
* [If the child is a custom component that wraps an <a> tag](#if-the-child-is-a-custom-component-that-wraps-an-a-tag)
* [If the child is a functional component](#if-the-child-is-a-functional-component)
* [With URL Object](#with-url-object)
* [Replace the URL instead of push](#replace-the-url-instead-of-push)
* [Disable scrolling to the top of the page](#disable-scrolling-to-the-top-of-the-page)
* [Middleware](#middleware)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/link.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)<Link>
<Link>
======
Examples
* [Hello World](https://github.com/vercel/next.js/tree/canary/examples/hello-world)
* [Active className on Link](https://github.com/vercel/next.js/tree/canary/examples/active-class-name)
`<Link>` is a React component that extends the HTML `<a>` element to provide [prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching) and client-side navigation between routes. It is the primary way to navigate between routes in Next.js.
For an example, consider a `pages` directory with the following files:
* `pages/index.js`
* `pages/about.js`
* `pages/blog/[slug].js`
We can have a link to each of these pages like so:
import Link from 'next/link'
function Home() {
return (
<ul>
<li>
<Link href="/">Home</Link>
</li>
<li>
<Link href="/about">About Us</Link>
</li>
<li>
<Link href="/blog/hello-world">Blog Post</Link>
</li>
</ul>
)
}
export default Home
[Props](#props)
---------------
Here's a summary of the props available for the Link Component:
Prop
Example
Type
Required
[`href`](#href-required)
`href="/dashboard"`
String or Object
Yes
[`replace`](#replace)
`replace={false}`
Boolean
\-
[`scroll`](#scroll)
`scroll={false}`
Boolean
\-
[`prefetch`](#prefetch)
`prefetch={false}`
Boolean
\-
> **Good to know**: `<a>` tag attributes such as `className` or `target="_blank"` can be added to `<Link>` as props and will be passed to the underlying `<a>` element.
### [`href` (required)](#href-required)
The path or URL to navigate to.
<Link href="/dashboard">Dashboard</Link>
`href` can also accept an object, for example:
// Navigate to /about?name=test
<Link
href={{
pathname: '/about',
query: { name: 'test' },
}}
>
About
</Link>
### [`replace`](#replace)
**Defaults to `false`.** When `true`, `next/link` will replace the current history state instead of adding a new URL into the [browser’s history](https://developer.mozilla.org/docs/Web/API/History_API) stack.
app/page.tsx
TypeScript
JavaScriptTypeScript
import Link from 'next/link'
export default function Page() {
return (
<Link href="/dashboard" replace>
Dashboard
</Link>
)
}
### [`scroll`](#scroll)
**Defaults to `true`.** The default behavior of `<Link>` **is to scroll to the top of a new route or to maintain the scroll position for backwards and forwards navigation.** When `false`, `next/link` will _not_ scroll to the top of the page after a navigation.
app/page.tsx
TypeScript
JavaScriptTypeScript
import Link from 'next/link'
export default function Page() {
return (
<Link href="/dashboard" scroll={false}>
Dashboard
</Link>
)
}
> **Good to know**:
>
> * Next.js will scroll to the [Page](/docs/app/building-your-application/routing/pages-and-layouts#pages) if it is not visible in the viewport upon navigation.
### [`prefetch`](#prefetch)
Prefetching happens when a `<Link />` component enters the user's viewport (initially or through scroll). Next.js prefetches and loads the linked route (denoted by the `href`) and data in the background to improve the performance of client-side navigations. Prefetching is only enabled in production.
* **`true` (default)**: The full route and its data will be prefetched.
* `false`: Prefetching will not happen when entering the viewport, but will happen on hover. If you want to completely remove fetching on hover as well, consider using an `<a>` tag or [incrementally adopting](/docs/app/building-your-application/upgrading/app-router-migration) the App Router, which enables disabling prefetching on hover too.
pages/index.tsx
TypeScript
JavaScriptTypeScript
import Link from 'next/link'
export default function Page() {
return (
<Link href="/dashboard" prefetch={false}>
Dashboard
</Link>
)
}
[Other Props](#other-props)
---------------------------
### [`legacyBehavior`](#legacybehavior)
An `<a>` element is no longer required as a child of `<Link>`. Add the `legacyBehavior` prop to use the legacy behavior or remove the `<a>` to upgrade. A [codemod is available](/docs/app/building-your-application/upgrading/codemods#new-link) to automatically upgrade your code.
> **Good to know**: when `legacyBehavior` is not set to `true`, all [`anchor`](https://developer.mozilla.org/docs/Web/HTML/Element/a) tag properties can be passed to `next/link` as well such as, `className`, `onClick`, etc.
### [`passHref`](#passhref)
Forces `Link` to send the `href` property to its child. Defaults to `false`
### [`scroll`](#scroll-1)
Scroll to the top of the page after a navigation. Defaults to `true`
### [`shallow`](#shallow)
Update the path of the current page without rerunning [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props), [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) or [`getInitialProps`](/docs/pages/api-reference/functions/get-initial-props). Defaults to `false`
### [`locale`](#locale)
The active locale is automatically prepended. `locale` allows for providing a different locale. When `false` `href` has to include the locale as the default behavior is disabled.
[Examples](#examples)
---------------------
### [Linking to Dynamic Routes](#linking-to-dynamic-routes)
For dynamic routes, it can be handy to use template literals to create the link's path.
For example, you can generate a list of links to the dynamic route `pages/blog/[slug].js`
pages/blog/index.js
import Link from 'next/link'
function Posts({ posts }) {
return (
<ul>
{posts.map((post) => (
<li key={post.id}>
<Link href={`/blog/${post.slug}`}>{post.title}</Link>
</li>
))}
</ul>
)
}
export default Posts
### [If the child is a custom component that wraps an `<a>` tag](#if-the-child-is-a-custom-component-that-wraps-an-a-tag)
If the child of `Link` is a custom component that wraps an `<a>` tag, you must add `passHref` to `Link`. This is necessary if you’re using libraries like [styled-components](https://styled-components.com/). Without this, the `<a>` tag will not have the `href` attribute, which hurts your site's accessibility and might affect SEO. If you're using [ESLint](/docs/pages/building-your-application/configuring/eslint#eslint-plugin), there is a built-in rule `next/link-passhref` to ensure correct usage of `passHref`.
import Link from 'next/link'
import styled from 'styled-components'
// This creates a custom component that wraps an <a> tag
const RedLink = styled.a`
color: red;
`
function NavLink({ href, name }) {
return (
<Link href={href} passHref legacyBehavior>
<RedLink>{name}</RedLink>
</Link>
)
}
export default NavLink
* If you’re using [emotion](https://emotion.sh/)’s JSX pragma feature (`@jsx jsx`), you must use `passHref` even if you use an `<a>` tag directly.
* The component should support `onClick` property to trigger navigation correctly
### [If the child is a functional component](#if-the-child-is-a-functional-component)
If the child of `Link` is a functional component, in addition to using `passHref` and `legacyBehavior`, you must wrap the component in [`React.forwardRef`](https://react.dev/reference/react/forwardRef):
import Link from 'next/link'
// `onClick`, `href`, and `ref` need to be passed to the DOM element
// for proper handling
const MyButton = React.forwardRef(({ onClick, href }, ref) => {
return (
<a href={href} onClick={onClick} ref={ref}>
Click Me
</a>
)
})
function Home() {
return (
<Link href="/about" passHref legacyBehavior>
<MyButton />
</Link>
)
}
export default Home
### [With URL Object](#with-url-object)
`Link` can also receive a URL object and it will automatically format it to create the URL string. Here's how to do it:
import Link from 'next/link'
function Home() {
return (
<ul>
<li>
<Link
href={{
pathname: '/about',
query: { name: 'test' },
}}
>
About us
</Link>
</li>
<li>
<Link
href={{
pathname: '/blog/[slug]',
query: { slug: 'my-post' },
}}
>
Blog Post
</Link>
</li>
</ul>
)
}
export default Home
The above example has a link to:
* A predefined route: `/about?name=test`
* A [dynamic route](/docs/app/building-your-application/routing/dynamic-routes): `/blog/my-post`
You can use every property as defined in the [Node.js URL module documentation](https://nodejs.org/api/url.html#url_url_strings_and_url_objects).
### [Replace the URL instead of push](#replace-the-url-instead-of-push)
The default behavior of the `Link` component is to `push` a new URL into the `history` stack. You can use the `replace` prop to prevent adding a new entry, as in the following example:
<Link href="/about" replace>
About us
</Link>
### [Disable scrolling to the top of the page](#disable-scrolling-to-the-top-of-the-page)
The default behavior of `Link` is to scroll to the top of the page. When there is a hash defined it will scroll to the specific id, like a normal `<a>` tag. To prevent scrolling to the top / hash `scroll={false}` can be added to `Link`:
<Link href="/#hashid" scroll={false}>
Disables scrolling to the top
</Link>
### [Middleware](#middleware)
It's common to use [Middleware](/docs/app/building-your-application/routing/middleware) for authentication or other purposes that involve rewriting the user to a different page. In order for the `<Link />` component to properly prefetch links with rewrites via Middleware, you need to tell Next.js both the URL to display and the URL to prefetch. This is required to avoid un-necessary fetches to middleware to know the correct route to prefetch.
For example, if you want to serve a `/dashboard` route that has authenticated and visitor views, you may add something similar to the following in your Middleware to redirect the user to the correct page:
middleware.js
export function middleware(req) {
const nextUrl = req.nextUrl
if (nextUrl.pathname === '/dashboard') {
if (req.cookies.authToken) {
return NextResponse.rewrite(new URL('/auth/dashboard', req.url))
} else {
return NextResponse.rewrite(new URL('/public/dashboard', req.url))
}
}
}
In this case, you would want to use the following code in your `<Link />` component:
import Link from 'next/link'
import useIsAuthed from './hooks/useIsAuthed'
export default function Page() {
const isAuthed = useIsAuthed()
const path = isAuthed ? '/auth/dashboard' : '/public/dashboard'
return (
<Link as="/dashboard" href={path}>
Dashboard
</Link>
)
}
> **Good to know**: If you're using [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes), you'll need to adapt your `as` and `href` props. For example, if you have a Dynamic Route like `/dashboard/authed/[user]` that you want to present differently via middleware, you would write: `<Link href={{ pathname: '/dashboard/authed/[user]', query: { user: username } }} as="/dashboard/[user]">Profile</Link>`.
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.0.0`
No longer requires a child `<a>` tag. A [codemod](/docs/app/building-your-application/upgrading/codemods#remove-a-tags-from-link-components) is provided to automatically update your codebase.
`v10.0.0`
`href` props pointing to a dynamic route are automatically resolved and no longer require an `as` prop.
`v8.0.0`
Improved prefetching performance.
`v1.0.0`
`next/link` introduced.
[Previous
<Image> (Legacy)
](/docs/pages/api-reference/components/image-legacy)
[Next
<Script>
](/docs/pages/api-reference/components/script)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"cc8ba65ed2a71c9e33421dac7214a6d9\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/head | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [
<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Avoid duplicated tags](#avoid-duplicated-tags)
* [Use minimal nesting](#use-minimal-nesting)
* [Use next/script for scripts](#use-nextscript-for-scripts)
* [No html or body tags](#no-html-or-body-tags)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/head.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)<Head>
<Head>
======
Examples
* [Head Elements](https://github.com/vercel/next.js/tree/canary/examples/head-elements)
* [Layout Component](https://github.com/vercel/next.js/tree/canary/examples/layout-component)
We expose a built-in component for appending elements to the `head` of the page:
import Head from 'next/head'
function IndexPage() {
return (
<div>
<Head>
<title>My page title</title>
</Head>
<p>Hello world!</p>
</div>
)
}
export default IndexPage
[Avoid duplicated tags](#avoid-duplicated-tags)
-----------------------------------------------
To avoid duplicate tags in your `head` you can use the `key` property, which will make sure the tag is only rendered once, as in the following example:
import Head from 'next/head'
function IndexPage() {
return (
<div>
<Head>
<title>My page title</title>
<meta property="og:title" content="My page title" key="title" />
</Head>
<Head>
<meta property="og:title" content="My new title" key="title" />
</Head>
<p>Hello world!</p>
</div>
)
}
export default IndexPage
In this case only the second `<meta property="og:title" />` is rendered. `meta` tags with duplicate `key` attributes are automatically handled.
> The contents of `head` get cleared upon unmounting the component, so make sure each page completely defines what it needs in `head`, without making assumptions about what other pages added.
[Use minimal nesting](#use-minimal-nesting)
-------------------------------------------
`title`, `meta` or any other elements (e.g. `script`) need to be contained as **direct** children of the `Head` element, or wrapped into maximum one level of `<React.Fragment>` or arrays—otherwise the tags won't be correctly picked up on client-side navigations.
[Use `next/script` for scripts](#use-nextscript-for-scripts)
------------------------------------------------------------
We recommend using [`next/script`](/docs/pages/building-your-application/optimizing/scripts) in your component instead of manually creating a `<script>` in `next/head`.
[No `html` or `body` tags](#no-html-or-body-tags)
-------------------------------------------------
You **cannot** use `<Head>` to set attributes on `<html>` or `<body>` tags. This will result in an `next-head-count is missing` error. `next/head` can only handle tags inside the HTML `<head>` tag.
[Previous
Font
](/docs/pages/api-reference/components/font)
[Next
<Image>
](/docs/pages/api-reference/components/image)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"747eaadfc21137c0ef59dbae5171d348\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/image | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [
<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Props](#props)
* [Required Props](#required-props)
* [src](#src)
* [width](#width)
* [height](#height)
* [alt](#alt)
* [Optional Props](#optional-props)
* [loader](#loader)
* [fill](#fill)
* [sizes](#sizes)
* [quality](#quality)
* [priority](#priority)
* [placeholder](#placeholder)
* [Advanced Props](#advanced-props)
* [style](#style)
* [onLoadingComplete](#onloadingcomplete)
* [onLoad](#onload)
* [onError](#onerror)
* [loading](#loading)
* [blurDataURL](#blurdataurl)
* [unoptimized](#unoptimized)
* [overrideSrc](#overridesrc)
* [Other Props](#other-props)
* [Configuration Options](#configuration-options)
* [remotePatterns](#remotepatterns)
* [domains](#domains)
* [loaderFile](#loaderfile)
* [Advanced](#advanced)
* [deviceSizes](#devicesizes)
* [imageSizes](#imagesizes)
* [formats](#formats)
* [Caching Behavior](#caching-behavior)
* [minimumCacheTTL](#minimumcachettl)
* [disableStaticImages](#disablestaticimages)
* [dangerouslyAllowSVG](#dangerouslyallowsvg)
* [Animated Images](#animated-images)
* [Responsive Images](#responsive-images)
* [Responsive image using a static import](#responsive-image-using-a-static-import)
* [Responsive image with aspect ratio](#responsive-image-with-aspect-ratio)
* [Responsive image with fill](#responsive-image-with-fill)
* [Theme Detection CSS](#theme-detection-css)
* [getImageProps](#getimageprops)
* [Theme Detection Picture](#theme-detection-picture)
* [Art Direction](#art-direction)
* [Background CSS](#background-css)
* [Known Browser Bugs](#known-browser-bugs)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/image.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)<Image>
<Image>
=======
Examples
* [Image Component](https://github.com/vercel/next.js/tree/canary/examples/image-component)
> **Good to know**: If you are using a version of Next.js prior to 13, you'll want to use the [next/legacy/image](/docs/pages/api-reference/components/image-legacy) documentation since the component was renamed.
This API reference will help you understand how to use [props](#props) and [configuration options](#configuration-options) available for the Image Component. For features and usage, please see the [Image Component](/docs/app/building-your-application/optimizing/images) page.
app/page.js
import Image from 'next/image'
export default function Page() {
return (
<Image
src="/profile.png"
width={500}
height={500}
alt="Picture of the author"
/>
)
}
[Props](#props)
---------------
Here's a summary of the props available for the Image Component:
Prop
Example
Type
Status
[`src`](#src)
`src="/profile.png"`
String
Required
[`width`](#width)
`width={500}`
Integer (px)
Required
[`height`](#height)
`height={500}`
Integer (px)
Required
[`alt`](#alt)
`alt="Picture of the author"`
String
Required
[`loader`](#loader)
`loader={imageLoader}`
Function
\-
[`fill`](#fill)
`fill={true}`
Boolean
\-
[`sizes`](#sizes)
`sizes="(max-width: 768px) 100vw, 33vw"`
String
\-
[`quality`](#quality)
`quality={80}`
Integer (1-100)
\-
[`priority`](#priority)
`priority={true}`
Boolean
\-
[`placeholder`](#placeholder)
`placeholder="blur"`
String
\-
[`style`](#style)
`style={{objectFit: "contain"}}`
Object
\-
[`onLoadingComplete`](#onloadingcomplete)
`onLoadingComplete={img => done())}`
Function
Deprecated
[`onLoad`](#onload)
`onLoad={event => done())}`
Function
\-
[`onError`](#onerror)
`onError(event => fail()}`
Function
\-
[`loading`](#loading)
`loading="lazy"`
String
\-
[`blurDataURL`](#blurdataurl)
`blurDataURL="data:image/jpeg..."`
String
\-
[`overrideSrc`](#overridesrc)
`overrideSrc="/seo.png"`
String
\-
[Required Props](#required-props)
---------------------------------
The Image Component requires the following properties: `src`, `width`, `height`, and `alt`.
app/page.js
import Image from 'next/image'
export default function Page() {
return (
<div>
<Image
src="/profile.png"
width={500}
height={500}
alt="Picture of the author"
/>
</div>
)
}
### [`src`](#src)
Must be one of the following:
* A [statically imported](/docs/app/building-your-application/optimizing/images#local-images) image file
* A path string. This can be either an absolute external URL, or an internal path depending on the [loader](#loader) prop.
When using an external URL, you must add it to [remotePatterns](#remotepatterns) in `next.config.js`.
### [`width`](#width)
The `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.
Required, except for [statically imported images](/docs/app/building-your-application/optimizing/images#local-images) or images with the [`fill` property](#fill).
### [`height`](#height)
The `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.
Required, except for [statically imported images](/docs/app/building-your-application/optimizing/images#local-images) or images with the [`fill` property](#fill).
### [`alt`](#alt)
The `alt` property is used to describe the image for screen readers and search engines. It is also the fallback text if images have been disabled or an error occurs while loading the image.
It should contain text that could replace the image [without changing the meaning of the page](https://html.spec.whatwg.org/multipage/images.html#general-guidelines). It is not meant to supplement the image and should not repeat information that is already provided in the captions above or below the image.
If the image is [purely decorative](https://html.spec.whatwg.org/multipage/images.html#a-purely-decorative-image-that-doesn't-add-any-information) or [not intended for the user](https://html.spec.whatwg.org/multipage/images.html#an-image-not-intended-for-the-user), the `alt` property should be an empty string (`alt=""`).
[Learn more](https://html.spec.whatwg.org/multipage/images.html#alt)
[Optional Props](#optional-props)
---------------------------------
The `<Image />` component accepts a number of additional properties beyond those which are required. This section describes the most commonly-used properties of the Image component. Find details about more rarely-used properties in the [Advanced Props](#advanced-props) section.
### [`loader`](#loader)
A custom function used to resolve image URLs.
A `loader` is a function returning a URL string for the image, given the following parameters:
* [`src`](#src)
* [`width`](#width)
* [`quality`](#quality)
Here is an example of using a custom loader:
import Image from 'next/image'
const imageLoader = ({ src, width, quality }) => {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
export default function Page() {
return (
<Image
loader={imageLoader}
src="me.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
}
Alternatively, you can use the [loaderFile](#loaderfile) configuration in `next.config.js` to configure every instance of `next/image` in your application, without passing a prop.
### [`fill`](#fill)
fill={true} // {true} | {false}
A boolean that causes the image to fill the parent element, which is useful when the [`width`](#width) and [`height`](#height) are unknown.
The parent element _must_ assign `position: "relative"`, `position: "fixed"`, or `position: "absolute"` style.
By default, the img element will automatically be assigned the `position: "absolute"` style.
If no styles are applied to the image, the image will stretch to fit the container. You may prefer to set `object-fit: "contain"` for an image which is letterboxed to fit the container and preserve aspect ratio.
Alternatively, `object-fit: "cover"` will cause the image to fill the entire container and be cropped to preserve aspect ratio. For this to look correct, the `overflow: "hidden"` style should be assigned to the parent element.
For more information, see also:
* [`position`](https://developer.mozilla.org/docs/Web/CSS/position)
* [`object-fit`](https://developer.mozilla.org/docs/Web/CSS/object-fit)
* [`object-position`](https://developer.mozilla.org/docs/Web/CSS/object-position)
### [`sizes`](#sizes)
A string, similar to a media query, that provides information about how wide the image will be at different breakpoints. The value of `sizes` will greatly affect performance for images using [`fill`](#fill) or which are [styled to have a responsive size](#responsive-images).
The `sizes` property serves two important purposes related to image performance:
* First, the value of `sizes` is used by the browser to determine which size of the image to download, from `next/image`'s automatically generated `srcset`. When the browser chooses, it does not yet know the size of the image on the page, so it selects an image that is the same size or larger than the viewport. The `sizes` property allows you to tell the browser that the image will actually be smaller than full screen. If you don't specify a `sizes` value in an image with the `fill` property, a default value of `100vw` (full screen width) is used.
* Second, the `sizes` property changes the behavior of the automatically generated `srcset` value. If no `sizes` value is present, a small `srcset` is generated, suitable for a fixed-size image (1x/2x/etc). If `sizes` is defined, a large `srcset` is generated, suitable for a responsive image (640w/750w/etc). If the `sizes` property includes sizes such as `50vw`, which represent a percentage of the viewport width, then the `srcset` is trimmed to not include any values which are too small to ever be necessary.
For example, if you know your styling will cause an image to be full-width on mobile devices, in a 2-column layout on tablets, and a 3-column layout on desktop displays, you should include a sizes property such as the following:
import Image from 'next/image'
export default function Page() {
return (
<div className="grid-element">
<Image
fill
src="/example.png"
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
/>
</div>
)
}
This example `sizes` could have a dramatic effect on performance metrics. Without the `33vw` sizes, the image selected from the server would be 3 times as wide as it needs to be. Because file size is proportional to the square of the width, without `sizes` the user would download an image that's 9 times larger than necessary.
Learn more about `srcset` and `sizes`:
* [web.dev](https://web.dev/learn/design/responsive-images/#sizes)
* [mdn](https://developer.mozilla.org/docs/Web/HTML/Element/img#sizes)
### [`quality`](#quality)
quality={75} // {number 1-100}
The quality of the optimized image, an integer between `1` and `100`, where `100` is the best quality and therefore largest file size. Defaults to `75`.
### [`priority`](#priority)
priority={false} // {false} | {true}
When true, the image will be considered high priority and [preload](https://web.dev/preload-responsive-images/). Lazy loading is automatically disabled for images using `priority`.
You should use the `priority` property on any image detected as the [Largest Contentful Paint (LCP)](https://nextjs.org/learn/seo/web-performance/lcp) element. It may be appropriate to have multiple priority images, as different images may be the LCP element for different viewport sizes.
Should only be used when the image is visible above the fold. Defaults to `false`.
### [`placeholder`](#placeholder)
placeholder = 'empty' // "empty" | "blur" | "data:image/..."
A placeholder to use while the image is loading. Possible values are `blur`, `empty`, or `data:image/...`. Defaults to `empty`.
When `blur`, the [`blurDataURL`](#blurdataurl) property will be used as the placeholder. If `src` is an object from a [static import](/docs/app/building-your-application/optimizing/images#local-images) and the imported image is `.jpg`, `.png`, `.webp`, or `.avif`, then `blurDataURL` will be automatically populated, except when the image is detected to be animated.
For dynamic images, you must provide the [`blurDataURL`](#blurdataurl) property. Solutions such as [Plaiceholder](https://github.com/joe-bell/plaiceholder) can help with `base64` generation.
When `data:image/...`, the [Data URL](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) will be used as the placeholder while the image is loading.
When `empty`, there will be no placeholder while the image is loading, only empty space.
Try it out:
* [Demo the `blur` placeholder](https://image-component.nextjs.gallery/placeholder)
* [Demo the shimmer effect with data URL `placeholder` prop](https://image-component.nextjs.gallery/shimmer)
* [Demo the color effect with `blurDataURL` prop](https://image-component.nextjs.gallery/color)
[Advanced Props](#advanced-props)
---------------------------------
In some cases, you may need more advanced usage. The `<Image />` component optionally accepts the following advanced properties.
### [`style`](#style)
Allows passing CSS styles to the underlying image element.
components/ProfileImage.js
const imageStyle = {
borderRadius: '50%',
border: '1px solid #fff',
}
export default function ProfileImage() {
return <Image src="..." style={imageStyle} />
}
Remember that the required width and height props can interact with your styling. If you use styling to modify an image's width, you should also style its height to `auto` to preserve its intrinsic aspect ratio, or your image will be distorted.
### [`onLoadingComplete`](#onloadingcomplete)
<Image onLoadingComplete={(img) => console.log(img.naturalWidth)} />
> **Warning**: Deprecated since Next.js 14 in favor of [`onLoad`](#onload).
A callback function that is invoked once the image is completely loaded and the [placeholder](#placeholder) has been removed.
The callback function will be called with one argument, a reference to the underlying `<img>` element.
### [`onLoad`](#onload)
<Image onLoad={(e) => console.log(e.target.naturalWidth)} />
A callback function that is invoked once the image is completely loaded and the [placeholder](#placeholder) has been removed.
The callback function will be called with one argument, the Event which has a `target` that references the underlying `<img>` element.
### [`onError`](#onerror)
<Image onError={(e) => console.error(e.target.id)} />
A callback function that is invoked if the image fails to load.
### [`loading`](#loading)
> **Recommendation**: This property is only meant for advanced use cases. Switching an image to load with `eager` will normally **hurt performance**. We recommend using the [`priority`](#priority) property instead, which will eagerly preload the image.
loading = 'lazy' // {lazy} | {eager}
The loading behavior of the image. Defaults to `lazy`.
When `lazy`, defer loading the image until it reaches a calculated distance from the viewport.
When `eager`, load the image immediately.
Learn more about the [`loading` attribute](https://developer.mozilla.org/docs/Web/HTML/Element/img#loading).
### [`blurDataURL`](#blurdataurl)
A [Data URL](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) to be used as a placeholder image before the `src` image successfully loads. Only takes effect when combined with [`placeholder="blur"`](#placeholder).
Must be a base64-encoded image. It will be enlarged and blurred, so a very small image (10px or less) is recommended. Including larger images as placeholders may harm your application performance.
Try it out:
* [Demo the default `blurDataURL` prop](https://image-component.nextjs.gallery/placeholder)
* [Demo the color effect with `blurDataURL` prop](https://image-component.nextjs.gallery/color)
You can also [generate a solid color Data URL](https://png-pixel.com) to match the image.
### [`unoptimized`](#unoptimized)
unoptimized = {false} // {false} | {true}
When true, the source image will be served as-is instead of changing quality, size, or format. Defaults to `false`.
import Image from 'next/image'
const UnoptimizedImage = (props) => {
return <Image {...props} unoptimized />
}
Since Next.js 12.3.0, this prop can be assigned to all images by updating `next.config.js` with the following configuration:
next.config.js
module.exports = {
images: {
unoptimized: true,
},
}
### [`overrideSrc`](#overridesrc)
When providing the `src` prop to the `<Image>` component, both the `srcset` and `src` attributes are generated automatically for the resulting `<img>`.
input.js
<Image src="/me.jpg" />
output.html
<img
srcset="
/_next/image?url=%2Fme.jpg&w=640&q=75 1x,
/_next/image?url=%2Fme.jpg&w=828&q=75 2x
"
src="/_next/image?url=%2Fme.jpg&w=828&q=75"
/>
In some cases, it is not desirable to have the `src` attribute generated and you may wish to override it using the `overrideSrc` prop.
For example, when upgrading an existing website from `<img>` to `<Image>`, you may wish to maintain the same `src` attribute for SEO purposes such as image ranking or avoiding recrawl.
input.js
<Image src="/me.jpg" overrideSrc="/override.jpg" />
output.html
<img
srcset="
/_next/image?url=%2Fme.jpg&w=640&q=75 1x,
/_next/image?url=%2Fme.jpg&w=828&q=75 2x
"
src="/override.jpg"
/>
### [Other Props](#other-props)
Other properties on the `<Image />` component will be passed to the underlying `img` element with the exception of the following:
* `srcSet`. Use [Device Sizes](#devicesizes) instead.
* `decoding`. It is always `"async"`.
[Configuration Options](#configuration-options)
-----------------------------------------------
In addition to props, you can configure the Image Component in `next.config.js`. The following options are available:
### [`remotePatterns`](#remotepatterns)
To protect your application from malicious users, configuration is required in order to use external images. This ensures that only external images from your account can be served from the Next.js Image Optimization API. These external images can be configured with the `remotePatterns` property in your `next.config.js` file, as shown below:
next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
port: '',
pathname: '/account123/**',
},
],
},
}
> **Good to know**: The example above will ensure the `src` property of `next/image` must start with `https://example.com/account123/`. Any other protocol, hostname, port, or unmatched path will respond with 400 Bad Request.
Below is another example of the `remotePatterns` property in the `next.config.js` file:
next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '**.example.com',
port: '',
},
],
},
}
> **Good to know**: The example above will ensure the `src` property of `next/image` must start with `https://img1.example.com` or `https://me.avatar.example.com` or any number of subdomains. Any other protocol, port, or unmatched hostname will respond with 400 Bad Request.
Wildcard patterns can be used for both `pathname` and `hostname` and have the following syntax:
* `*` match a single path segment or subdomain
* `**` match any number of path segments at the end or subdomains at the beginning
The `**` syntax does not work in the middle of the pattern.
> **Good to know**: When omitting `protocol`, `port` or `pathname`, then the wildcard `**` is implied. This is not recommended because it may allow malicious actors to optimize urls you did not intend.
### [`domains`](#domains)
> **Warning**: Deprecated since Next.js 14 in favor of strict [`remotePatterns`](#remotepatterns) in order to protect your application from malicious users. Only use `domains` if you own all the content served from the domain.
Similar to [`remotePatterns`](#remotepatterns), the `domains` configuration can be used to provide a list of allowed hostnames for external images.
However, the `domains` configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.
Below is an example of the `domains` property in the `next.config.js` file:
next.config.js
module.exports = {
images: {
domains: ['assets.acme.com'],
},
}
### [`loaderFile`](#loaderfile)
If you want to use a cloud provider to optimize images instead of using the Next.js built-in Image Optimization API, you can configure the `loaderFile` in your `next.config.js` like the following:
next.config.js
module.exports = {
images: {
loader: 'custom',
loaderFile: './my/image/loader.js',
},
}
This must point to a file relative to the root of your Next.js application. The file must export a default function that returns a string, for example:
my/image/loader.js
export default function myImageLoader({ src, width, quality }) {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
Alternatively, you can use the [`loader` prop](#loader) to configure each instance of `next/image`.
Examples:
* [Custom Image Loader Configuration](/docs/app/api-reference/next-config-js/images#example-loader-configuration)
[Advanced](#advanced)
---------------------
The following configuration is for advanced use cases and is usually not necessary. If you choose to configure the properties below, you will override any changes to the Next.js defaults in future updates.
### [`deviceSizes`](#devicesizes)
If you know the expected device widths of your users, you can specify a list of device width breakpoints using the `deviceSizes` property in `next.config.js`. These widths are used when the `next/image` component uses [`sizes`](#sizes) prop to ensure the correct image is served for user's device.
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
},
}
### [`imageSizes`](#imagesizes)
You can specify a list of image widths using the `images.imageSizes` property in your `next.config.js` file. These widths are concatenated with the array of [device sizes](#devicesizes) to form the full array of sizes used to generate image [srcset](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/srcset)s.
The reason there are two separate lists is that imageSizes is only used for images which provide a [`sizes`](#sizes) prop, which indicates that the image is less than the full width of the screen. **Therefore, the sizes in imageSizes should all be smaller than the smallest size in deviceSizes.**
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
}
### [`formats`](#formats)
The default [Image Optimization API](#loader) will automatically detect the browser's supported image formats via the request's `Accept` header.
If the `Accept` head matches more than one of the configured formats, the first match in the array is used. Therefore, the array order matters. If there is no match (or the source image is [animated](#animated-images)), the Image Optimization API will fallback to the original image's format.
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
formats: ['image/webp'],
},
}
You can enable AVIF support with the following configuration.
next.config.js
module.exports = {
images: {
formats: ['image/avif', 'image/webp'],
},
}
> **Good to know**:
>
> * AVIF generally takes 20% longer to encode but it compresses 20% smaller compared to WebP. This means that the first time an image is requested, it will typically be slower and then subsequent requests that are cached will be faster.
> * If you self-host with a Proxy/CDN in front of Next.js, you must configure the Proxy to forward the `Accept` header.
[Caching Behavior](#caching-behavior)
-------------------------------------
The following describes the caching algorithm for the default [loader](#loader). For all other loaders, please refer to your cloud provider's documentation.
Images are optimized dynamically upon request and stored in the `<distDir>/cache/images` directory. The optimized image file will be served for subsequent requests until the expiration is reached. When a request is made that matches a cached but expired file, the expired image is served stale immediately. Then the image is optimized again in the background (also called revalidation) and saved to the cache with the new expiration date.
The cache status of an image can be determined by reading the value of the `x-nextjs-cache` response header. The possible values are the following:
* `MISS` - the path is not in the cache (occurs at most once, on the first visit)
* `STALE` - the path is in the cache but exceeded the revalidate time so it will be updated in the background
* `HIT` - the path is in the cache and has not exceeded the revalidate time
The expiration (or rather Max Age) is defined by either the [`minimumCacheTTL`](#minimumcachettl) configuration or the upstream image `Cache-Control` header, whichever is larger. Specifically, the `max-age` value of the `Cache-Control` header is used. If both `s-maxage` and `max-age` are found, then `s-maxage` is preferred. The `max-age` is also passed-through to any downstream clients including CDNs and browsers.
* You can configure [`minimumCacheTTL`](#minimumcachettl) to increase the cache duration when the upstream image does not include `Cache-Control` header or the value is very low.
* You can configure [`deviceSizes`](#devicesizes) and [`imageSizes`](#imagesizes) to reduce the total number of possible generated images.
* You can configure [formats](#formats) to disable multiple formats in favor of a single image format.
### [`minimumCacheTTL`](#minimumcachettl)
You can configure the Time to Live (TTL) in seconds for cached optimized images. In many cases, it's better to use a [Static Image Import](/docs/app/building-your-application/optimizing/images#local-images) which will automatically hash the file contents and cache the image forever with a `Cache-Control` header of `immutable`.
next.config.js
module.exports = {
images: {
minimumCacheTTL: 60,
},
}
The expiration (or rather Max Age) of the optimized image is defined by either the `minimumCacheTTL` or the upstream image `Cache-Control` header, whichever is larger.
If you need to change the caching behavior per image, you can configure [`headers`](/docs/app/api-reference/next-config-js/headers) to set the `Cache-Control` header on the upstream image (e.g. `/some-asset.jpg`, not `/_next/image` itself).
There is no mechanism to invalidate the cache at this time, so its best to keep `minimumCacheTTL` low. Otherwise you may need to manually change the [`src`](#src) prop or delete `<distDir>/cache/images`.
### [`disableStaticImages`](#disablestaticimages)
The default behavior allows you to import static files such as `import icon from './icon.png'` and then pass that to the `src` property.
In some cases, you may wish to disable this feature if it conflicts with other plugins that expect the import to behave differently.
You can disable static image imports inside your `next.config.js`:
next.config.js
module.exports = {
images: {
disableStaticImages: true,
},
}
### [`dangerouslyAllowSVG`](#dangerouslyallowsvg)
The default [loader](#loader) does not optimize SVG images for a few reasons. First, SVG is a vector format meaning it can be resized losslessly. Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper [Content Security Policy (CSP) headers](/docs/app/api-reference/next-config-js/headers#content-security-policy).
Therefore, we recommended using the [`unoptimized`](#unoptimized) prop when the [`src`](#src) prop is known to be SVG. This happens automatically when `src` ends with `".svg"`.
However, if you need to serve SVG images with the default Image Optimization API, you can set `dangerouslyAllowSVG` inside your `next.config.js`:
next.config.js
module.exports = {
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
}
In addition, it is strongly recommended to also set `contentDispositionType` to force the browser to download the image, as well as `contentSecurityPolicy` to prevent scripts embedded in the image from executing.
[Animated Images](#animated-images)
-----------------------------------
The default [loader](#loader) will automatically bypass Image Optimization for animated images and serve the image as-is.
Auto-detection for animated files is best-effort and supports GIF, APNG, and WebP. If you want to explicitly bypass Image Optimization for a given animated image, use the [unoptimized](#unoptimized) prop.
[Responsive Images](#responsive-images)
---------------------------------------
The default generated `srcset` contains `1x` and `2x` images in order to support different device pixel ratios. However, you may wish to render a responsive image that stretches with the viewport. In that case, you'll need to set [`sizes`](#sizes) as well as `style` (or `className`).
You can render a responsive image using one of the following methods below.
### [Responsive image using a static import](#responsive-image-using-a-static-import)
If the source image is not dynamic, you can statically import to create a responsive image:
components/author.js
import Image from 'next/image'
import me from '../photos/me.jpg'
export default function Author() {
return (
<Image
src={me}
alt="Picture of the author"
sizes="100vw"
style={{
width: '100%',
height: 'auto',
}}
/>
)
}
Try it out:
* [Demo the image responsive to viewport](https://image-component.nextjs.gallery/responsive)
### [Responsive image with aspect ratio](#responsive-image-with-aspect-ratio)
If the source image is a dynamic or a remote url, you will also need to provide `width` and `height` to set the correct aspect ratio of the responsive image:
components/page.js
import Image from 'next/image'
export default function Page({ photoUrl }) {
return (
<Image
src={photoUrl}
alt="Picture of the author"
sizes="100vw"
style={{
width: '100%',
height: 'auto',
}}
width={500}
height={300}
/>
)
}
Try it out:
* [Demo the image responsive to viewport](https://image-component.nextjs.gallery/responsive)
### [Responsive image with `fill`](#responsive-image-with-fill)
If you don't know the aspect ratio, you will need to set the [`fill`](#fill) prop and set `position: relative` on the parent. Optionally, you can set `object-fit` style depending on the desired stretch vs crop behavior:
app/page.js
import Image from 'next/image'
export default function Page({ photoUrl }) {
return (
<div style={{ position: 'relative', width: '300px', height: '500px' }}>
<Image
src={photoUrl}
alt="Picture of the author"
sizes="300px"
fill
style={{
objectFit: 'contain',
}}
/>
</div>
)
}
Try it out:
* [Demo the `fill` prop](https://image-component.nextjs.gallery/fill)
[Theme Detection CSS](#theme-detection-css)
-------------------------------------------
If you want to display a different image for light and dark mode, you can create a new component that wraps two `<Image>` components and reveals the correct one based on a CSS media query.
components/theme-image.module.css
.imgDark {
display: none;
}
@media (prefers-color-scheme: dark) {
.imgLight {
display: none;
}
.imgDark {
display: unset;
}
}
components/theme-image.tsx
TypeScript
JavaScriptTypeScript
import styles from './theme-image.module.css'
import Image, { ImageProps } from 'next/image'
type Props = Omit<ImageProps, 'src' | 'priority' | 'loading'> & {
srcLight: string
srcDark: string
}
const ThemeImage = (props: Props) => {
const { srcLight, srcDark, ...rest } = props
return (
<>
<Image {...rest} src={srcLight} className={styles.imgLight} />
<Image {...rest} src={srcDark} className={styles.imgDark} />
</>
)
}
> **Good to know**: The default behavior of `loading="lazy"` ensures that only the correct image is loaded. You cannot use `priority` or `loading="eager"` because that would cause both images to load. Instead, you can use [`fetchPriority="high"`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/fetchPriority).
Try it out:
* [Demo light/dark mode theme detection](https://image-component.nextjs.gallery/theme)
[getImageProps](#getimageprops)
-------------------------------
For more advanced use cases, you can call `getImageProps()` to get the props that would be passed to the underlying `<img>` element, and instead pass to them to another component, style, canvas, etc.
This also avoid calling React `useState()` so it can lead to better performance, but it cannot be used with the [`placeholder`](#placeholder) prop because the placeholder will never be removed.
### [Theme Detection Picture](#theme-detection-picture)
If you want to display a different image for light and dark mode, you can use the [`<picture>`](https://developer.mozilla.org/docs/Web/HTML/Element/picture) element to display a different image based on the user's [preferred color scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme).
app/page.js
import { getImageProps } from 'next/image'
export default function Page() {
const common = { alt: 'Theme Example', width: 800, height: 400 }
const {
props: { srcSet: dark },
} = getImageProps({ ...common, src: '/dark.png' })
const {
props: { srcSet: light, ...rest },
} = getImageProps({ ...common, src: '/light.png' })
return (
<picture>
<source media="(prefers-color-scheme: dark)" srcSet={dark} />
<source media="(prefers-color-scheme: light)" srcSet={light} />
<img {...rest} />
</picture>
)
}
### [Art Direction](#art-direction)
If you want to display a different image for mobile and desktop, sometimes called [Art Direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction), you can provide different `src`, `width`, `height`, and `quality` props to `getImageProps()`.
app/page.js
import { getImageProps } from 'next/image'
export default function Home() {
const common = { alt: 'Art Direction Example', sizes: '100vw' }
const {
props: { srcSet: desktop },
} = getImageProps({
...common,
width: 1440,
height: 875,
quality: 80,
src: '/desktop.jpg',
})
const {
props: { srcSet: mobile, ...rest },
} = getImageProps({
...common,
width: 750,
height: 1334,
quality: 70,
src: '/mobile.jpg',
})
return (
<picture>
<source media="(min-width: 1000px)" srcSet={desktop} />
<source media="(min-width: 500px)" srcSet={mobile} />
<img {...rest} style={{ width: '100%', height: 'auto' }} />
</picture>
)
}
### [Background CSS](#background-css)
You can even convert the `srcSet` string to the [`image-set()`](https://developer.mozilla.org/en-US/docs/Web/CSS/image/image-set) CSS function to optimize a background image.
app/page.js
import { getImageProps } from 'next/image'
function getBackgroundImage(srcSet = '') {
const imageSet = srcSet
.split(', ')
.map((str) => {
const [url, dpi] = str.split(' ')
return `url("${url}") ${dpi}`
})
.join(', ')
return `image-set(${imageSet})`
}
export default function Home() {
const {
props: { srcSet },
} = getImageProps({ alt: '', width: 128, height: 128, src: '/img.png' })
const backgroundImage = getBackgroundImage(srcSet)
const style = { height: '100vh', width: '100vw', backgroundImage }
return (
<main style={style}>
<h1>Hello World</h1>
</main>
)
}
[Known Browser Bugs](#known-browser-bugs)
-----------------------------------------
This `next/image` component uses browser native [lazy loading](https://caniuse.com/loading-lazy-attr), which may fallback to eager loading for older browsers before Safari 15.4. When using the blur-up placeholder, older browsers before Safari 12 will fallback to empty placeholder. When using styles with `width`/`height` of `auto`, it is possible to cause [Layout Shift](https://web.dev/cls/) on older browsers before Safari 15 that don't [preserve the aspect ratio](https://caniuse.com/mdn-html_elements_img_aspect_ratio_computed_from_attributes). For more details, see [this MDN video](https://www.youtube.com/watch?v=4-d_SoCHeWE).
* [Safari 15 - 16.3](https://bugs.webkit.org/show_bug.cgi?id=243601) display a gray border while loading. Safari 16.4 [fixed this issue](https://webkit.org/blog/13966/webkit-features-in-safari-16-4/#:~:text=Now%20in%20Safari%2016.4%2C%20a%20gray%20line%20no%20longer%20appears%20to%20mark%20the%20space%20where%20a%20lazy%2Dloaded%20image%20will%20appear%20once%20it%E2%80%99s%20been%20loaded.). Possible solutions:
* Use CSS `@supports (font: -apple-system-body) and (-webkit-appearance: none) { img[loading="lazy"] { clip-path: inset(0.6px) } }`
* Use [`priority`](#priority) if the image is above the fold
* [Firefox 67+](https://bugzilla.mozilla.org/show_bug.cgi?id=1556156) displays a white background while loading. Possible solutions:
* Enable [AVIF `formats`](#formats)
* Use [`placeholder`](#placeholder)
[Version History](#version-history)
-----------------------------------
Version
Changes
`v14.2.0`
`overrideSrc` prop added.
`v14.1.0`
`getImageProps()` is stable.
`v14.0.0`
`onLoadingComplete` prop and `domains` config deprecated.
`v13.4.14`
`placeholder` prop support for `data:/image...`
`v13.2.0`
`contentDispositionType` configuration added.
`v13.0.6`
`ref` prop added.
`v13.0.0`
The `next/image` import was renamed to `next/legacy/image`. The `next/future/image` import was renamed to `next/image`. A [codemod is available](/docs/app/building-your-application/upgrading/codemods#next-image-to-legacy-image) to safely and automatically rename your imports. `<span>` wrapper removed. `layout`, `objectFit`, `objectPosition`, `lazyBoundary`, `lazyRoot` props removed. `alt` is required. `onLoadingComplete` receives reference to `img` element. Built-in loader config removed.
`v12.3.0`
`remotePatterns` and `unoptimized` configuration is stable.
`v12.2.0`
Experimental `remotePatterns` and experimental `unoptimized` configuration added. `layout="raw"` removed.
`v12.1.1`
`style` prop added. Experimental support for `layout="raw"` added.
`v12.1.0`
`dangerouslyAllowSVG` and `contentSecurityPolicy` configuration added.
`v12.0.9`
`lazyRoot` prop added.
`v12.0.0`
`formats` configuration added.
AVIF support added.
Wrapper `<div>` changed to `<span>`.
`v11.1.0`
`onLoadingComplete` and `lazyBoundary` props added.
`v11.0.0`
`src` prop support for static import.
`placeholder` prop added.
`blurDataURL` prop added.
`v10.0.5`
`loader` prop added.
`v10.0.1`
`layout` prop added.
`v10.0.0`
`next/image` introduced.
[Previous
<Head>
](/docs/pages/api-reference/components/head)
[Next
<Image> (Legacy)
](/docs/pages/api-reference/components/image-legacy)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"fd8ace86ce69b9f5b3ebbf8a41c4c79c\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/script | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [
<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Props](#props)
* [Required Props](#required-props)
* [src](#src)
* [Optional Props](#optional-props)
* [strategy](#strategy)
* [beforeInteractive](#beforeinteractive)
* [afterInteractive](#afterinteractive)
* [lazyOnload](#lazyonload)
* [worker](#worker)
* [onLoad](#onload)
* [onReady](#onready)
* [onError](#onerror)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/script.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)<Script>
<Script>
========
This API reference will help you understand how to use [props](#props) available for the Script Component. For features and usage, please see the [Optimizing Scripts](/docs/app/building-your-application/optimizing/scripts) page.
app/dashboard/page.tsx
TypeScript
JavaScriptTypeScript
import Script from 'next/script'
export default function Dashboard() {
return (
<>
<Script src="https://example.com/script.js" />
</>
)
}
[Props](#props)
---------------
Here's a summary of the props available for the Script Component:
Prop
Example
Type
Required
[`src`](#src)
`src="http://example.com/script"`
String
Required unless inline script is used
[`strategy`](#strategy)
`strategy="lazyOnload"`
String
\-
[`onLoad`](#onload)
`onLoad={onLoadFunc}`
Function
\-
[`onReady`](#onready)
`onReady={onReadyFunc}`
Function
\-
[`onError`](#onerror)
`onError={onErrorFunc}`
Function
\-
[Required Props](#required-props)
---------------------------------
The `<Script />` component requires the following properties.
### [`src`](#src)
A path string specifying the URL of an external script. This can be either an absolute external URL or an internal path. The `src` property is required unless an inline script is used.
[Optional Props](#optional-props)
---------------------------------
The `<Script />` component accepts a number of additional properties beyond those which are required.
### [`strategy`](#strategy)
The loading strategy of the script. There are four different strategies that can be used:
* `beforeInteractive`: Load before any Next.js code and before any page hydration occurs.
* `afterInteractive`: (**default**) Load early but after some hydration on the page occurs.
* `lazyOnload`: Load during browser idle time.
* `worker`: (experimental) Load in a web worker.
### [`beforeInteractive`](#beforeinteractive)
Scripts that load with the `beforeInteractive` strategy are injected into the initial HTML from the server, downloaded before any Next.js module, and executed in the order they are placed before _any_ hydration occurs on the page.
Scripts denoted with this strategy are preloaded and fetched before any first-party code, but their execution does not block page hydration from occurring.
`beforeInteractive` scripts must be placed inside the `Document` Component (`pages/_document.js`) and are designed to load scripts that are needed by the entire site (i.e. the script will load when any page in the application has been loaded server-side).
**This strategy should only be used for critical scripts that need to be fetched before any part of the page becomes interactive.**
pages/\_document.js
import { Html, Head, Main, NextScript } from 'next/document'
import Script from 'next/script'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
/>
</body>
</Html>
)
}
> **Good to know**: Scripts with `beforeInteractive` will always be injected inside the `head` of the HTML document regardless of where it's placed in the component.
Some examples of scripts that should be loaded as soon as possible with `beforeInteractive` include:
* Bot detectors
* Cookie consent managers
### [`afterInteractive`](#afterinteractive)
Scripts that use the `afterInteractive` strategy are injected into the HTML client-side and will load after some (or all) hydration occurs on the page. **This is the default strategy** of the Script component and should be used for any script that needs to load as soon as possible but not before any first-party Next.js code.
`afterInteractive` scripts can be placed inside of any page or layout and will only load and execute when that page (or group of pages) is opened in the browser.
app/page.js
import Script from 'next/script'
export default function Page() {
return (
<>
<Script src="https://example.com/script.js" strategy="afterInteractive" />
</>
)
}
Some examples of scripts that are good candidates for `afterInteractive` include:
* Tag managers
* Analytics
### [`lazyOnload`](#lazyonload)
Scripts that use the `lazyOnload` strategy are injected into the HTML client-side during browser idle time and will load after all resources on the page have been fetched. This strategy should be used for any background or low priority scripts that do not need to load early.
`lazyOnload` scripts can be placed inside of any page or layout and will only load and execute when that page (or group of pages) is opened in the browser.
app/page.js
import Script from 'next/script'
export default function Page() {
return (
<>
<Script src="https://example.com/script.js" strategy="lazyOnload" />
</>
)
}
Examples of scripts that do not need to load immediately and can be fetched with `lazyOnload` include:
* Chat support plugins
* Social media widgets
### [`worker`](#worker)
> **Warning:** The `worker` strategy is not yet stable and does not yet work with the [`app`](/docs/app/building-your-application/routing/defining-routes) directory. Use with caution.
Scripts that use the `worker` strategy are off-loaded to a web worker in order to free up the main thread and ensure that only critical, first-party resources are processed on it. While this strategy can be used for any script, it is an advanced use case that is not guaranteed to support all third-party scripts.
To use `worker` as a strategy, the `nextScriptWorkers` flag must be enabled in `next.config.js`:
next.config.js
module.exports = {
experimental: {
nextScriptWorkers: true,
},
}
`worker` scripts can **only currently be used in the `pages/` directory**:
pages/home.tsx
TypeScript
JavaScriptTypeScript
import Script from 'next/script'
export default function Home() {
return (
<>
<Script src="https://example.com/script.js" strategy="worker" />
</>
)
}
### [`onLoad`](#onload)
> **Warning:** `onLoad` does not yet work with Server Components and can only be used in Client Components. Further, `onLoad` can't be used with `beforeInteractive` – consider using `onReady` instead.
Some third-party scripts require users to run JavaScript code once after the script has finished loading in order to instantiate content or call a function. If you are loading a script with either afterInteractive or lazyOnload as a loading strategy, you can execute code after it has loaded using the onLoad property.
Here's an example of executing a lodash method only after the library has been loaded.
app/page.tsx
TypeScript
JavaScriptTypeScript
'use client'
import Script from 'next/script'
export default function Page() {
return (
<>
<Script
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"
onLoad={() => {
console.log(_.sample([1, 2, 3, 4]))
}}
/>
</>
)
}
### [`onReady`](#onready)
> **Warning:** `onReady` does not yet work with Server Components and can only be used in Client Components.
Some third-party scripts require users to run JavaScript code after the script has finished loading and every time the component is mounted (after a route navigation for example). You can execute code after the script's load event when it first loads and then after every subsequent component re-mount using the onReady property.
Here's an example of how to re-instantiate a Google Maps JS embed every time the component is mounted:
import { useRef } from 'react'
import Script from 'next/script'
export default function Page() {
const mapRef = useRef()
return (
<>
<div ref={mapRef}></div>
<Script
id="google-maps"
src="https://maps.googleapis.com/maps/api/js"
onReady={() => {
new google.maps.Map(mapRef.current, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
})
}}
/>
</>
)
}
### [`onError`](#onerror)
> **Warning:** `onError` does not yet work with Server Components and can only be used in Client Components. `onError` cannot be used with the `beforeInteractive` loading strategy.
Sometimes it is helpful to catch when a script fails to load. These errors can be handled with the onError property:
import Script from 'next/script'
export default function Page() {
return (
<>
<Script
src="https://example.com/script.js"
onError={(e: Error) => {
console.error('Script failed to load', e)
}}
/>
</>
)
}
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.0.0`
`beforeInteractive` and `afterInteractive` is modified to support `app`.
`v12.2.4`
`onReady` prop added.
`v12.2.2`
Allow `next/script` with `beforeInteractive` to be placed in `_document`.
`v11.0.0`
`next/script` introduced.
[Previous
<Link>
](/docs/pages/api-reference/components/link)
[Next
Functions
](/docs/pages/api-reference/functions)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"dda86608a994826980cf869103854f87\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)Functions
Functions
=========
[
### getInitialProps
Fetch dynamic data on the server for your React component with getInitialProps.
](/docs/pages/api-reference/functions/get-initial-props)[
### getServerSideProps
API reference for \`getServerSideProps\`. Learn how to fetch data on each request with Next.js.
](/docs/pages/api-reference/functions/get-server-side-props)[
### getStaticPaths
API reference for \`getStaticPaths\`. Learn how to fetch data and generate static pages with \`getStaticPaths\`.
](/docs/pages/api-reference/functions/get-static-paths)[
### getStaticProps
API reference for \`getStaticProps\`. Learn how to use \`getStaticProps\` to generate static pages with Next.js.
](/docs/pages/api-reference/functions/get-static-props)[
### NextRequest
API Reference for NextRequest.
](/docs/pages/api-reference/functions/next-request)[
### NextResponse
API Reference for NextResponse.
](/docs/pages/api-reference/functions/next-response)[
### useAmp
Enable AMP in a page, and control the way Next.js adds AMP to the page with the AMP config.
](/docs/pages/api-reference/functions/use-amp)[
### useReportWebVitals
useReportWebVitals
](/docs/pages/api-reference/functions/use-report-web-vitals)[
### useRouter
Learn more about the API of the Next.js Router, and access the router instance in your page with the useRouter hook.
](/docs/pages/api-reference/functions/use-router)[
### userAgent
The userAgent helper extends the Web Request API with additional properties and methods to interact with the user agent object from the request.
](/docs/pages/api-reference/functions/userAgent)
[Previous
<Script>
](/docs/pages/api-reference/components/script)
[Next
getInitialProps
](/docs/pages/api-reference/functions/get-initial-props)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"7681569c5b4a185b3900a89345cebba7\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/app/api-reference/next-config-js/poweredByHeader | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [
poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/02-app/02-api-reference/05-next-config-js/poweredByHeader.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[App Router](/docs/app)[...](/docs/app/api-reference)[next.config.js Options](/docs/app/api-reference/next-config-js)poweredByHeader
poweredByHeader
===============
By default Next.js will add the `x-powered-by` header. To opt-out of it, open `next.config.js` and disable the `poweredByHeader` config:
next.config.js
module.exports = {
poweredByHeader: false,
}
[Previous
Partial Prerendering (experimental)
](/docs/app/api-reference/next-config-js/partial-prerendering)
[Next
productionBrowserSourceMaps
](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"9d2ff144336e0e988925d10790887993\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/components/image-legacy | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [
<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Comparison](#comparison)
* [Required Props](#required-props)
* [src](#src)
* [width](#width)
* [height](#height)
* [Optional Props](#optional-props)
* [layout](#layout)
* [loader](#loader)
* [sizes](#sizes)
* [quality](#quality)
* [priority](#priority)
* [placeholder](#placeholder)
* [Advanced Props](#advanced-props)
* [style](#style)
* [objectFit](#objectfit)
* [objectPosition](#objectposition)
* [onLoadingComplete](#onloadingcomplete)
* [loading](#loading)
* [blurDataURL](#blurdataurl)
* [lazyBoundary](#lazyboundary)
* [lazyRoot](#lazyroot)
* [unoptimized](#unoptimized)
* [Other Props](#other-props)
* [Configuration Options](#configuration-options)
* [Remote Patterns](#remote-patterns)
* [Domains](#domains)
* [Loader Configuration](#loader-configuration)
* [Built-in Loaders](#built-in-loaders)
* [Advanced](#advanced)
* [Device Sizes](#device-sizes)
* [Image Sizes](#image-sizes)
* [Acceptable Formats](#acceptable-formats)
* [Caching Behavior](#caching-behavior)
* [Minimum Cache TTL](#minimum-cache-ttl)
* [Disable Static Imports](#disable-static-imports)
* [Dangerously Allow SVG](#dangerously-allow-svg)
* [Animated Images](#animated-images)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/01-components/image-legacy.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Components](/docs/pages/api-reference/components)<Image> (Legacy)
<Image> (Legacy)
================
Examples
* [Legacy Image Component](https://github.com/vercel/next.js/tree/canary/examples/image-legacy-component)
Starting with Next.js 13, the `next/image` component was rewritten to improve both the performance and developer experience. In order to provide a backwards compatible upgrade solution, the old `next/image` was renamed to `next/legacy/image`.
View the **new** [`next/image` API Reference](/docs/pages/api-reference/components/image)
[Comparison](#comparison)
-------------------------
Compared to `next/legacy/image`, the new `next/image` component has the following changes:
* Removes `<span>` wrapper around `<img>` in favor of [native computed aspect ratio](https://caniuse.com/mdn-html_elements_img_aspect_ratio_computed_from_attributes)
* Adds support for canonical `style` prop
* Removes `layout` prop in favor of `style` or `className`
* Removes `objectFit` prop in favor of `style` or `className`
* Removes `objectPosition` prop in favor of `style` or `className`
* Removes `IntersectionObserver` implementation in favor of [native lazy loading](https://caniuse.com/loading-lazy-attr)
* Removes `lazyBoundary` prop since there is no native equivalent
* Removes `lazyRoot` prop since there is no native equivalent
* Removes `loader` config in favor of [`loader`](#loader) prop
* Changed `alt` prop from optional to required
* Changed `onLoadingComplete` callback to receive reference to `<img>` element
[Required Props](#required-props)
---------------------------------
The `<Image />` component requires the following properties.
### [src](#src)
Must be one of the following:
* A [statically imported](/docs/pages/building-your-application/optimizing/images#local-images) image file
* A path string. This can be either an absolute external URL, or an internal path depending on the [loader](#loader) prop or [loader configuration](#loader-configuration).
When using an external URL, you must add it to [remotePatterns](#remote-patterns) in `next.config.js`.
### [width](#width)
The `width` property can represent either the _rendered_ width or _original_ width in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.
When using `layout="intrinsic"` or `layout="fixed"` the `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.
When using `layout="responsive"`, `layout="fill"`, the `width` property represents the _original_ width in pixels, so it will only affect the aspect ratio.
The `width` property is required, except for [statically imported images](/docs/pages/building-your-application/optimizing/images#local-images), or those with `layout="fill"`.
### [height](#height)
The `height` property can represent either the _rendered_ height or _original_ height in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.
When using `layout="intrinsic"` or `layout="fixed"` the `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.
When using `layout="responsive"`, `layout="fill"`, the `height` property represents the _original_ height in pixels, so it will only affect the aspect ratio.
The `height` property is required, except for [statically imported images](/docs/pages/building-your-application/optimizing/images#local-images), or those with `layout="fill"`.
[Optional Props](#optional-props)
---------------------------------
The `<Image />` component accepts a number of additional properties beyond those which are required. This section describes the most commonly-used properties of the Image component. Find details about more rarely-used properties in the [Advanced Props](#advanced-props) section.
### [layout](#layout)
The layout behavior of the image as the viewport changes size.
`layout`
Behavior
`srcSet`
`sizes`
Has wrapper and sizer
`intrinsic` (default)
Scale _down_ to fit width of container, up to image size
`1x`, `2x` (based on [imageSizes](#image-sizes))
N/A
yes
`fixed`
Sized to `width` and `height` exactly
`1x`, `2x` (based on [imageSizes](#image-sizes))
N/A
yes
`responsive`
Scale to fit width of container
`640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes))
`100vw`
yes
`fill`
Grow in both X and Y axes to fill container
`640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes))
`100vw`
yes
* [Demo the `intrinsic` layout (default)](https://image-legacy-component.nextjs.gallery/layout-intrinsic)
* When `intrinsic`, the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports.
* [Demo the `fixed` layout](https://image-legacy-component.nextjs.gallery/layout-fixed)
* When `fixed`, the image dimensions will not change as the viewport changes (no responsiveness) similar to the native `img` element.
* [Demo the `responsive` layout](https://image-legacy-component.nextjs.gallery/layout-responsive)
* When `responsive`, the image will scale the dimensions down for smaller viewports and scale up for larger viewports.
* Ensure the parent element uses `display: block` in their stylesheet.
* [Demo the `fill` layout](https://image-legacy-component.nextjs.gallery/layout-fill)
* When `fill`, the image will stretch both width and height to the dimensions of the parent element, provided the parent element is relative.
* This is usually paired with the [`objectFit`](#objectfit) property.
* Ensure the parent element has `position: relative` in their stylesheet.
* [Demo background image](https://image-legacy-component.nextjs.gallery/background)
### [loader](#loader)
A custom function used to resolve URLs. Setting the loader as a prop on the Image component overrides the default loader defined in the [`images` section of `next.config.js`](#loader-configuration).
A `loader` is a function returning a URL string for the image, given the following parameters:
* [`src`](#src)
* [`width`](#width)
* [`quality`](#quality)
Here is an example of using a custom loader:
import Image from 'next/legacy/image'
const myLoader = ({ src, width, quality }) => {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
const MyImage = (props) => {
return (
<Image
loader={myLoader}
src="me.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
}
### [sizes](#sizes)
A string that provides information about how wide the image will be at different breakpoints. The value of `sizes` will greatly affect performance for images using `layout="responsive"` or `layout="fill"`. It will be ignored for images using `layout="intrinsic"` or `layout="fixed"`.
The `sizes` property serves two important purposes related to image performance:
First, the value of `sizes` is used by the browser to determine which size of the image to download, from `next/legacy/image`'s automatically-generated source set. When the browser chooses, it does not yet know the size of the image on the page, so it selects an image that is the same size or larger than the viewport. The `sizes` property allows you to tell the browser that the image will actually be smaller than full screen. If you don't specify a `sizes` value, a default value of `100vw` (full screen width) is used.
Second, the `sizes` value is parsed and used to trim the values in the automatically-created source set. If the `sizes` property includes sizes such as `50vw`, which represent a percentage of the viewport width, then the source set is trimmed to not include any values which are too small to ever be necessary.
For example, if you know your styling will cause an image to be full-width on mobile devices, in a 2-column layout on tablets, and a 3-column layout on desktop displays, you should include a sizes property such as the following:
import Image from 'next/legacy/image'
const Example = () => (
<div className="grid-element">
<Image
src="/example.png"
layout="fill"
sizes="(max-width: 768px) 100vw,
(max-width: 1200px) 50vw,
33vw"
/>
</div>
)
This example `sizes` could have a dramatic effect on performance metrics. Without the `33vw` sizes, the image selected from the server would be 3 times as wide as it needs to be. Because file size is proportional to the square of the width, without `sizes` the user would download an image that's 9 times larger than necessary.
Learn more about `srcset` and `sizes`:
* [web.dev](https://web.dev/learn/design/responsive-images/#sizes)
* [mdn](https://developer.mozilla.org/docs/Web/HTML/Element/img#attr-sizes)
### [quality](#quality)
The quality of the optimized image, an integer between `1` and `100` where `100` is the best quality. Defaults to `75`.
### [priority](#priority)
When true, the image will be considered high priority and [preload](https://web.dev/preload-responsive-images/). Lazy loading is automatically disabled for images using `priority`.
You should use the `priority` property on any image detected as the [Largest Contentful Paint (LCP)](https://nextjs.org/learn/seo/web-performance/lcp) element. It may be appropriate to have multiple priority images, as different images may be the LCP element for different viewport sizes.
Should only be used when the image is visible above the fold. Defaults to `false`.
### [placeholder](#placeholder)
A placeholder to use while the image is loading. Possible values are `blur` or `empty`. Defaults to `empty`.
When `blur`, the [`blurDataURL`](#blurdataurl) property will be used as the placeholder. If `src` is an object from a [static import](/docs/pages/building-your-application/optimizing/images#local-images) and the imported image is `.jpg`, `.png`, `.webp`, or `.avif`, then `blurDataURL` will be automatically populated.
For dynamic images, you must provide the [`blurDataURL`](#blurdataurl) property. Solutions such as [Plaiceholder](https://github.com/joe-bell/plaiceholder) can help with `base64` generation.
When `empty`, there will be no placeholder while the image is loading, only empty space.
Try it out:
* [Demo the `blur` placeholder](https://image-legacy-component.nextjs.gallery/placeholder)
* [Demo the shimmer effect with `blurDataURL` prop](https://image-legacy-component.nextjs.gallery/shimmer)
* [Demo the color effect with `blurDataURL` prop](https://image-legacy-component.nextjs.gallery/color)
[Advanced Props](#advanced-props)
---------------------------------
In some cases, you may need more advanced usage. The `<Image />` component optionally accepts the following advanced properties.
### [style](#style)
Allows [passing CSS styles](https://developer.mozilla.org/docs/Web/HTML/Element/style) to the underlying image element.
Note that all `layout` modes apply their own styles to the image element, and these automatic styles take precedence over the `style` prop.
Also keep in mind that the required `width` and `height` props can interact with your styling. If you use styling to modify an image's `width`, you must set the `height="auto"` style as well, or your image will be distorted.
### [objectFit](#objectfit)
Defines how the image will fit into its parent container when using `layout="fill"`.
This value is passed to the [object-fit CSS property](https://developer.mozilla.org/docs/Web/CSS/object-fit) for the `src` image.
### [objectPosition](#objectposition)
Defines how the image is positioned within its parent element when using `layout="fill"`.
This value is passed to the [object-position CSS property](https://developer.mozilla.org/docs/Web/CSS/object-position) applied to the image.
### [onLoadingComplete](#onloadingcomplete)
A callback function that is invoked once the image is completely loaded and the [placeholder](#placeholder) has been removed.
The `onLoadingComplete` function accepts one parameter, an object with the following properties:
* [`naturalWidth`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalWidth)
* [`naturalHeight`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalHeight)
### [loading](#loading)
> **Attention**: This property is only meant for advanced usage. Switching an image to load with `eager` will normally **hurt performance**.
>
> We recommend using the [`priority`](#priority) property instead, which properly loads the image eagerly for nearly all use cases.
The loading behavior of the image. Defaults to `lazy`.
When `lazy`, defer loading the image until it reaches a calculated distance from the viewport.
When `eager`, load the image immediately.
[Learn more](https://developer.mozilla.org/docs/Web/HTML/Element/img#attr-loading)
### [blurDataURL](#blurdataurl)
A [Data URL](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) to be used as a placeholder image before the `src` image successfully loads. Only takes effect when combined with [`placeholder="blur"`](#placeholder).
Must be a base64-encoded image. It will be enlarged and blurred, so a very small image (10px or less) is recommended. Including larger images as placeholders may harm your application performance.
Try it out:
* [Demo the default `blurDataURL` prop](https://image-legacy-component.nextjs.gallery/placeholder)
* [Demo the shimmer effect with `blurDataURL` prop](https://image-legacy-component.nextjs.gallery/shimmer)
* [Demo the color effect with `blurDataURL` prop](https://image-legacy-component.nextjs.gallery/color)
You can also [generate a solid color Data URL](https://png-pixel.com) to match the image.
### [lazyBoundary](#lazyboundary)
A string (with similar syntax to the margin property) that acts as the bounding box used to detect the intersection of the viewport with the image and trigger lazy [loading](#loading). Defaults to `"200px"`.
If the image is nested in a scrollable parent element other than the root document, you will also need to assign the [lazyRoot](#lazyroot) prop.
[Learn more](https://developer.mozilla.org/docs/Web/API/IntersectionObserver/rootMargin)
### [lazyRoot](#lazyroot)
A React [Ref](https://react.dev/learn/referencing-values-with-refs) pointing to the scrollable parent element. Defaults to `null` (the document viewport).
The Ref must point to a DOM element or a React component that [forwards the Ref](https://react.dev/reference/react/forwardRef) to the underlying DOM element.
**Example pointing to a DOM element**
import Image from 'next/legacy/image'
import React from 'react'
const Example = () => {
const lazyRoot = React.useRef(null)
return (
<div ref={lazyRoot} style={{ overflowX: 'scroll', width: '500px' }}>
<Image lazyRoot={lazyRoot} src="/one.jpg" width="500" height="500" />
<Image lazyRoot={lazyRoot} src="/two.jpg" width="500" height="500" />
</div>
)
}
**Example pointing to a React component**
import Image from 'next/legacy/image'
import React from 'react'
const Container = React.forwardRef((props, ref) => {
return (
<div ref={ref} style={{ overflowX: 'scroll', width: '500px' }}>
{props.children}
</div>
)
})
const Example = () => {
const lazyRoot = React.useRef(null)
return (
<Container ref={lazyRoot}>
<Image lazyRoot={lazyRoot} src="/one.jpg" width="500" height="500" />
<Image lazyRoot={lazyRoot} src="/two.jpg" width="500" height="500" />
</Container>
)
}
[Learn more](https://developer.mozilla.org/docs/Web/API/IntersectionObserver/root)
### [unoptimized](#unoptimized)
When true, the source image will be served as-is instead of changing quality, size, or format. Defaults to `false`.
import Image from 'next/image'
const UnoptimizedImage = (props) => {
return <Image {...props} unoptimized />
}
Since Next.js 12.3.0, this prop can be assigned to all images by updating `next.config.js` with the following configuration:
next.config.js
module.exports = {
images: {
unoptimized: true,
},
}
[Other Props](#other-props)
---------------------------
Other properties on the `<Image />` component will be passed to the underlying `img` element with the exception of the following:
* `srcSet`. Use [Device Sizes](#device-sizes) instead.
* `ref`. Use [`onLoadingComplete`](#onloadingcomplete) instead.
* `decoding`. It is always `"async"`.
[Configuration Options](#configuration-options)
-----------------------------------------------
### [Remote Patterns](#remote-patterns)
To protect your application from malicious users, configuration is required in order to use external images. This ensures that only external images from your account can be served from the Next.js Image Optimization API. These external images can be configured with the `remotePatterns` property in your `next.config.js` file, as shown below:
next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
port: '',
pathname: '/account123/**',
},
],
},
}
> **Good to know**: The example above will ensure the `src` property of `next/legacy/image` must start with `https://example.com/account123/`. Any other protocol, hostname, port, or unmatched path will respond with 400 Bad Request.
Below is another example of the `remotePatterns` property in the `next.config.js` file:
next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '**.example.com',
port: '',
},
],
},
}
> **Good to know**: The example above will ensure the `src` property of `next/legacy/image` must start with `https://img1.example.com` or `https://me.avatar.example.com` or any number of subdomains. Any other protocol, port, or unmatched hostname will respond with 400 Bad Request.
Wildcard patterns can be used for both `pathname` and `hostname` and have the following syntax:
* `*` match a single path segment or subdomain
* `**` match any number of path segments at the end or subdomains at the beginning
The `**` syntax does not work in the middle of the pattern.
> **Good to know**: When omitting `protocol`, `port` or `pathname`, then the wildcard `**` is implied. This is not recommended because it may allow malicious actors to optimize urls you did not intend.
### [Domains](#domains)
> **Warning**: Deprecated since Next.js 14 in favor of strict [`remotePatterns`](#remote-patterns) in order to protect your application from malicious users. Only use `domains` if you own all the content served from the domain.
Similar to [`remotePatterns`](#remote-patterns), the `domains` configuration can be used to provide a list of allowed hostnames for external images.
However, the `domains` configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.
Below is an example of the `domains` property in the `next.config.js` file:
next.config.js
module.exports = {
images: {
domains: ['assets.acme.com'],
},
}
### [Loader Configuration](#loader-configuration)
If you want to use a cloud provider to optimize images instead of using the Next.js built-in Image Optimization API, you can configure the `loader` and `path` prefix in your `next.config.js` file. This allows you to use relative URLs for the Image [`src`](#src) and automatically generate the correct absolute URL for your provider.
next.config.js
module.exports = {
images: {
loader: 'imgix',
path: 'https://example.com/myaccount/',
},
}
### [Built-in Loaders](#built-in-loaders)
The following Image Optimization cloud providers are included:
* Default: Works automatically with `next dev`, `next start`, or a custom server
* [Vercel](https://vercel.com): Works automatically when you deploy on Vercel, no configuration necessary. [Learn more](https://vercel.com/docs/concepts/image-optimization?utm_source=next-site&utm_medium=docs&utm_campaign=next-website)
* [Imgix](https://www.imgix.com): `loader: 'imgix'`
* [Cloudinary](https://cloudinary.com): `loader: 'cloudinary'`
* [Akamai](https://www.akamai.com): `loader: 'akamai'`
* Custom: `loader: 'custom'` use a custom cloud provider by implementing the [`loader`](#loader) prop on the `next/legacy/image` component
If you need a different provider, you can use the [`loader`](#loader) prop with `next/legacy/image`.
> Images can not be optimized at build time using [`output: 'export'`](/docs/pages/building-your-application/deploying/static-exports), only on-demand. To use `next/legacy/image` with `output: 'export'`, you will need to use a different loader than the default. [Read more in the discussion.](https://github.com/vercel/next.js/discussions/19065)
> The `next/legacy/image` component's default loader uses [`squoosh`](https://www.npmjs.com/package/@squoosh/lib) because it is quick to install and suitable for a development environment. When using `next start` in your production environment, it is strongly recommended that you install [`sharp`](https://www.npmjs.com/package/sharp) by running `npm i sharp` in your project directory. This is not necessary for Vercel deployments, as `sharp` is installed automatically.
[Advanced](#advanced)
---------------------
The following configuration is for advanced use cases and is usually not necessary. If you choose to configure the properties below, you will override any changes to the Next.js defaults in future updates.
### [Device Sizes](#device-sizes)
If you know the expected device widths of your users, you can specify a list of device width breakpoints using the `deviceSizes` property in `next.config.js`. These widths are used when the `next/legacy/image` component uses `layout="responsive"` or `layout="fill"` to ensure the correct image is served for user's device.
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
},
}
### [Image Sizes](#image-sizes)
You can specify a list of image widths using the `images.imageSizes` property in your `next.config.js` file. These widths are concatenated with the array of [device sizes](#device-sizes) to form the full array of sizes used to generate image [srcset](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/srcset)s.
The reason there are two separate lists is that imageSizes is only used for images which provide a [`sizes`](#sizes) prop, which indicates that the image is less than the full width of the screen. **Therefore, the sizes in imageSizes should all be smaller than the smallest size in deviceSizes.**
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
}
### [Acceptable Formats](#acceptable-formats)
The default [Image Optimization API](#loader-configuration) will automatically detect the browser's supported image formats via the request's `Accept` header.
If the `Accept` head matches more than one of the configured formats, the first match in the array is used. Therefore, the array order matters. If there is no match (or the source image is [animated](#animated-images)), the Image Optimization API will fallback to the original image's format.
If no configuration is provided, the default below is used.
next.config.js
module.exports = {
images: {
formats: ['image/webp'],
},
}
You can enable AVIF support with the following configuration.
next.config.js
module.exports = {
images: {
formats: ['image/avif', 'image/webp'],
},
}
> **Good to know**: AVIF generally takes 20% longer to encode but it compresses 20% smaller compared to WebP. This means that the first time an image is requested, it will typically be slower and then subsequent requests that are cached will be faster.
[Caching Behavior](#caching-behavior)
-------------------------------------
The following describes the caching algorithm for the default [loader](#loader). For all other loaders, please refer to your cloud provider's documentation.
Images are optimized dynamically upon request and stored in the `<distDir>/cache/images` directory. The optimized image file will be served for subsequent requests until the expiration is reached. When a request is made that matches a cached but expired file, the expired image is served stale immediately. Then the image is optimized again in the background (also called revalidation) and saved to the cache with the new expiration date.
The cache status of an image can be determined by reading the value of the `x-nextjs-cache` (`x-vercel-cache` when deployed on Vercel) response header. The possible values are the following:
* `MISS` - the path is not in the cache (occurs at most once, on the first visit)
* `STALE` - the path is in the cache but exceeded the revalidate time so it will be updated in the background
* `HIT` - the path is in the cache and has not exceeded the revalidate time
The expiration (or rather Max Age) is defined by either the [`minimumCacheTTL`](#minimum-cache-ttl) configuration or the upstream image `Cache-Control` header, whichever is larger. Specifically, the `max-age` value of the `Cache-Control` header is used. If both `s-maxage` and `max-age` are found, then `s-maxage` is preferred. The `max-age` is also passed-through to any downstream clients including CDNs and browsers.
* You can configure [`minimumCacheTTL`](#minimum-cache-ttl) to increase the cache duration when the upstream image does not include `Cache-Control` header or the value is very low.
* You can configure [`deviceSizes`](#device-sizes) and [`imageSizes`](#image-sizes) to reduce the total number of possible generated images.
* You can configure [formats](#acceptable-formats) to disable multiple formats in favor of a single image format.
### [Minimum Cache TTL](#minimum-cache-ttl)
You can configure the Time to Live (TTL) in seconds for cached optimized images. In many cases, it's better to use a [Static Image Import](/docs/pages/building-your-application/optimizing/images#local-images) which will automatically hash the file contents and cache the image forever with a `Cache-Control` header of `immutable`.
next.config.js
module.exports = {
images: {
minimumCacheTTL: 60,
},
}
The expiration (or rather Max Age) of the optimized image is defined by either the `minimumCacheTTL` or the upstream image `Cache-Control` header, whichever is larger.
If you need to change the caching behavior per image, you can configure [`headers`](/docs/pages/api-reference/next-config-js/headers) to set the `Cache-Control` header on the upstream image (e.g. `/some-asset.jpg`, not `/_next/image` itself).
There is no mechanism to invalidate the cache at this time, so its best to keep `minimumCacheTTL` low. Otherwise you may need to manually change the [`src`](#src) prop or delete `<distDir>/cache/images`.
### [Disable Static Imports](#disable-static-imports)
The default behavior allows you to import static files such as `import icon from './icon.png'` and then pass that to the `src` property.
In some cases, you may wish to disable this feature if it conflicts with other plugins that expect the import to behave differently.
You can disable static image imports inside your `next.config.js`:
next.config.js
module.exports = {
images: {
disableStaticImages: true,
},
}
### [Dangerously Allow SVG](#dangerously-allow-svg)
The default [loader](#loader) does not optimize SVG images for a few reasons. First, SVG is a vector format meaning it can be resized losslessly. Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper [Content Security Policy (CSP) headers](/docs/app/api-reference/next-config-js/headers#content-security-policy).
Therefore, we recommended using the [`unoptimized`](#unoptimized) prop when the [`src`](#src) prop is known to be SVG. This happens automatically when `src` ends with `".svg"`.
However, if you need to serve SVG images with the default Image Optimization API, you can set `dangerouslyAllowSVG` inside your `next.config.js`:
next.config.js
module.exports = {
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
}
In addition, it is strongly recommended to also set `contentDispositionType` to force the browser to download the image, as well as `contentSecurityPolicy` to prevent scripts embedded in the image from executing.
### [Animated Images](#animated-images)
The default [loader](#loader) will automatically bypass Image Optimization for animated images and serve the image as-is.
Auto-detection for animated files is best-effort and supports GIF, APNG, and WebP. If you want to explicitly bypass Image Optimization for a given animated image, use the [unoptimized](#unoptimized) prop.
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.0.0`
`next/image` renamed to `next/legacy/image`
[Previous
<Image>
](/docs/pages/api-reference/components/image)
[Next
<Link>
](/docs/pages/api-reference/components/link)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"e5a4d89577f07316aa91caf69d502fd2\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/get-initial-props | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [
getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Context Object](#context-object)
* [Caveats](#caveats)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/get-initial-props.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)getInitialProps
getInitialProps
===============
> **Good to know**: `getInitialProps` is a legacy API. We recommend using [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) or [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) instead.
`getInitialProps` is an `async` function that can be added to the default exported React component for the page. It will run on both the server-side and again on the client-side during page transitions. The result of the function will be forwarded to the React component as `props`.
pages/index.tsx
TypeScript
JavaScriptTypeScript
import { NextPageContext } from 'next'
Page.getInitialProps = async (ctx: NextPageContext) => {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const json = await res.json()
return { stars: json.stargazers_count }
}
export default function Page({ stars }: { stars: number }) {
return stars
}
> **Good to know**:
>
> * Data returned from `getInitialProps` is serialized when server rendering. Ensure the returned object from `getInitialProps` is a plain `Object`, and not using `Date`, `Map` or `Set`.
> * For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then also run on the client when navigating to a different route with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router).
> * If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will also run on the server.
[Context Object](#context-object)
---------------------------------
`getInitialProps` receives a single argument called `context`, which is an object with the following properties:
Name
Description
`pathname`
Current route, the path of the page in `/pages`
`query`
Query string of the URL, parsed as an object
`asPath`
`String` of the actual path (including the query) shown in the browser
`req`
[HTTP request object](https://nodejs.org/api/http.html#http_class_http_incomingmessage) (server only)
`res`
[HTTP response object](https://nodejs.org/api/http.html#http_class_http_serverresponse) (server only)
`err`
Error object if any error is encountered during the rendering
[Caveats](#caveats)
-------------------
* `getInitialProps` can only be used in `pages/` top level files, and not in nested components. To have nested data fetching at the component level, consider exploring the [App Router](/docs/app/building-your-application/data-fetching).
* Regardless of whether your route is static or dynamic, any data returned from `getInitialProps` as `props` will be able to be examined on the client-side in the initial HTML. This is to allow the page to be [hydrated](https://react.dev/reference/react-dom/hydrate) correctly. Make sure that you don't pass any sensitive information that shouldn't be available on the client in `props`.
[Previous
Functions
](/docs/pages/api-reference/functions)
[Next
getServerSideProps
](/docs/pages/api-reference/functions/get-server-side-props)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"1a5bf90d89a0eddd8789939103a5c456\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/get-static-paths | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [
getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [getStaticPaths return values](#getstaticpaths-return-values)
* [paths](#paths)
* [fallback: false](#fallback-false)
* [fallback: true](#fallback-true)
* [When is fallback: true useful?](#when-is-fallback-true-useful)
* [fallback: 'blocking'](#fallback-blocking)
* [Fallback pages](#fallback-pages)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/get-static-paths.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)getStaticPaths
getStaticPaths
==============
When exporting a function called `getStaticPaths` from a page that uses [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes), Next.js will statically pre-render all the paths specified by `getStaticPaths`.
pages/repo/\[name\].tsx
TypeScript
JavaScriptTypeScript
import type {
InferGetStaticPropsType,
GetStaticProps,
GetStaticPaths,
} from 'next'
type Repo = {
name: string
stargazers_count: number
}
export const getStaticPaths = (async () => {
return {
paths: [
{
params: {
name: 'next.js',
},
}, // See the "paths" section below
],
fallback: true, // false or "blocking"
}
}) satisfies GetStaticPaths
export const getStaticProps = (async (context) => {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = await res.json()
return { props: { repo } }
}) satisfies GetStaticProps<{
repo: Repo
}>
export default function Page({
repo,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return repo.stargazers_count
}
[getStaticPaths return values](#getstaticpaths-return-values)
-------------------------------------------------------------
The `getStaticPaths` function should return an object with the following **required** properties:
### [`paths`](#paths)
The `paths` key determines which paths will be pre-rendered. For example, suppose that you have a page that uses [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes) named `pages/posts/[id].js`. If you export `getStaticPaths` from this page and return the following for `paths`:
return {
paths: [
{ params: { id: '1' }},
{
params: { id: '2' },
// with i18n configured the locale for the path can be returned as well
locale: "en",
},
],
fallback: ...
}
Then, Next.js will statically generate `/posts/1` and `/posts/2` during `next build` using the page component in `pages/posts/[id].js`.
The value for each `params` object must match the parameters used in the page name:
* If the page name is `pages/posts/[postId]/[commentId]`, then `params` should contain `postId` and `commentId`.
* If the page name uses [catch-all routes](/docs/pages/building-your-application/routing/dynamic-routes#catch-all-segments) like `pages/[...slug]`, then `params` should contain `slug` (which is an array). If this array is `['hello', 'world']`, then Next.js will statically generate the page at `/hello/world`.
* If the page uses an [optional catch-all route](/docs/pages/building-your-application/routing/dynamic-routes#optional-catch-all-segments), use `null`, `[]`, `undefined` or `false` to render the root-most route. For example, if you supply `slug: false` for `pages/[[...slug]]`, Next.js will statically generate the page `/`.
The `params` strings are **case-sensitive** and ideally should be normalized to ensure the paths are generated correctly. For example, if `WoRLD` is returned for a param it will only match if `WoRLD` is the actual path visited, not `world` or `World`.
Separate of the `params` object a `locale` field can be returned when [i18n is configured](/docs/pages/building-your-application/routing/internationalization), which configures the locale for the path being generated.
### [`fallback: false`](#fallback-false)
If `fallback` is `false`, then any paths not returned by `getStaticPaths` will result in a **404 page**.
When `next build` is run, Next.js will check if `getStaticPaths` returned `fallback: false`, it will then build **only** the paths returned by `getStaticPaths`. This option is useful if you have a small number of paths to create, or new page data is not added often. If you find that you need to add more paths, and you have `fallback: false`, you will need to run `next build` again so that the new paths can be generated.
The following example pre-renders one blog post per page called `pages/posts/[id].js`. The list of blog posts will be fetched from a CMS and returned by `getStaticPaths`. Then, for each page, it fetches the post data from a CMS using [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props).
pages/posts/\[id\].js
function Post({ post }) {
// Render post...
}
// This function gets called at build time
export async function getStaticPaths() {
// Call an external API endpoint to get posts
const res = await fetch('https://.../posts')
const posts = await res.json()
// Get the paths we want to pre-render based on posts
const paths = posts.map((post) => ({
params: { id: post.id },
}))
// We'll pre-render only these paths at build time.
// { fallback: false } means other routes should 404.
return { paths, fallback: false }
}
// This also gets called at build time
export async function getStaticProps({ params }) {
// params contains the post `id`.
// If the route is like /posts/1, then params.id is 1
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
// Pass post data to the page via props
return { props: { post } }
}
export default Post
### [`fallback: true`](#fallback-true)
Examples
* [Static generation of a large number of pages](https://static-tweet.vercel.app)
If `fallback` is `true`, then the behavior of `getStaticProps` changes in the following ways:
* The paths returned from `getStaticPaths` will be rendered to `HTML` at build time by `getStaticProps`.
* The paths that have not been generated at build time will **not** result in a 404 page. Instead, Next.js will serve a [“fallback”](#fallback-pages) version of the page on the first request to such a path. Web crawlers, such as Google, won't be served a fallback and instead the path will behave as in [`fallback: 'blocking'`](#fallback-blocking).
* When a page with `fallback: true` is navigated to through `next/link` or `next/router` (client-side) Next.js will _not_ serve a fallback and instead the page will behave as [`fallback: 'blocking'`](#fallback-blocking).
* In the background, Next.js will statically generate the requested path `HTML` and `JSON`. This includes running `getStaticProps`.
* When complete, the browser receives the `JSON` for the generated path. This will be used to automatically render the page with the required props. From the user’s perspective, the page will be swapped from the fallback page to the full page.
* At the same time, Next.js adds this path to the list of pre-rendered pages. Subsequent requests to the same path will serve the generated page, like other pages pre-rendered at build time.
> **Good to know**: `fallback: true` is not supported when using [`output: 'export'`](/docs/pages/building-your-application/deploying/static-exports).
#### [When is `fallback: true` useful?](#when-is-fallback-true-useful)
`fallback: true` is useful if your app has a very large number of static pages that depend on data (such as a very large e-commerce site). If you want to pre-render all product pages, the builds would take a very long time.
Instead, you may statically generate a small subset of pages and use `fallback: true` for the rest. When someone requests a page that is not generated yet, the user will see the page with a loading indicator or skeleton component.
Shortly after, `getStaticProps` finishes and the page will be rendered with the requested data. From now on, everyone who requests the same page will get the statically pre-rendered page.
This ensures that users always have a fast experience while preserving fast builds and the benefits of Static Generation.
`fallback: true` will not _update_ generated pages, for that take a look at [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration).
### [`fallback: 'blocking'`](#fallback-blocking)
If `fallback` is `'blocking'`, new paths not returned by `getStaticPaths` will wait for the `HTML` to be generated, identical to SSR (hence why _blocking_), and then be cached for future requests so it only happens once per path.
`getStaticProps` will behave as follows:
* The paths returned from `getStaticPaths` will be rendered to `HTML` at build time by `getStaticProps`.
* The paths that have not been generated at build time will **not** result in a 404 page. Instead, Next.js will SSR on the first request and return the generated `HTML`.
* When complete, the browser receives the `HTML` for the generated path. From the user’s perspective, it will transition from "the browser is requesting the page" to "the full page is loaded". There is no flash of loading/fallback state.
* At the same time, Next.js adds this path to the list of pre-rendered pages. Subsequent requests to the same path will serve the generated page, like other pages pre-rendered at build time.
`fallback: 'blocking'` will not _update_ generated pages by default. To update generated pages, use [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration) in conjunction with `fallback: 'blocking'`.
> **Good to know**: `fallback: 'blocking'` is not supported when using [`output: 'export'`](/docs/pages/building-your-application/deploying/static-exports).
### [Fallback pages](#fallback-pages)
In the “fallback” version of a page:
* The page’s props will be empty.
* Using the [router](/docs/pages/api-reference/functions/use-router), you can detect if the fallback is being rendered, `router.isFallback` will be `true`.
The following example showcases using `isFallback`:
pages/posts/\[id\].js
import { useRouter } from 'next/router'
function Post({ post }) {
const router = useRouter()
// If the page is not yet generated, this will be displayed
// initially until getStaticProps() finishes running
if (router.isFallback) {
return <div>Loading...</div>
}
// Render post...
}
// This function gets called at build time
export async function getStaticPaths() {
return {
// Only `/posts/1` and `/posts/2` are generated at build time
paths: [{ params: { id: '1' } }, { params: { id: '2' } }],
// Enable statically generating additional pages
// For example: `/posts/3`
fallback: true,
}
}
// This also gets called at build time
export async function getStaticProps({ params }) {
// params contains the post `id`.
// If the route is like /posts/1, then params.id is 1
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
// Pass post data to the page via props
return {
props: { post },
// Re-generate the post at most once per second
// if a request comes in
revalidate: 1,
}
}
export default Post
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.4.0`
[App Router](/docs/app/building-your-application/data-fetching) is now stable with simplified data fetching, including [`generateStaticParams()`](/docs/app/api-reference/functions/generate-static-params)
`v12.2.0`
[On-Demand Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation) is stable.
`v12.1.0`
[On-Demand Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation) added (beta).
`v9.5.0`
Stable [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
`v9.3.0`
`getStaticPaths` introduced.
[Previous
getServerSideProps
](/docs/pages/api-reference/functions/get-server-side-props)
[Next
getStaticProps
](/docs/pages/api-reference/functions/get-static-props)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f30f4a2af357457b2dc5a4d03da0f547\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/use-amp | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [
useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [AMP First Page](#amp-first-page)
* [Hybrid AMP Page](#hybrid-amp-page)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/use-amp.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)useAmp
useAmp
======
Examples
* [AMP](https://github.com/vercel/next.js/tree/canary/examples/amp)
> AMP support is one of our advanced features, you can [read more about AMP here](/docs/pages/building-your-application/configuring/amp).
To enable AMP, add the following config to your page:
pages/index.js
export const config = { amp: true }
The `amp` config accepts the following values:
* `true` - The page will be AMP-only
* `'hybrid'` - The page will have two versions, one with AMP and another one with HTML
To learn more about the `amp` config, read the sections below.
[AMP First Page](#amp-first-page)
---------------------------------
Take a look at the following example:
pages/about.js
export const config = { amp: true }
function About(props) {
return <h3>My AMP About Page!</h3>
}
export default About
The page above is an AMP-only page, which means:
* The page has no Next.js or React client-side runtime
* The page is automatically optimized with [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer), an optimizer that applies the same transformations as AMP caches (improves performance by up to 42%)
* The page has a user-accessible (optimized) version of the page and a search-engine indexable (unoptimized) version of the page
[Hybrid AMP Page](#hybrid-amp-page)
-----------------------------------
Take a look at the following example:
pages/about.js
import { useAmp } from 'next/amp'
export const config = { amp: 'hybrid' }
function About(props) {
const isAmp = useAmp()
return (
<div>
<h3>My AMP About Page!</h3>
{isAmp ? (
<amp-img
width="300"
height="300"
src="/my-img.jpg"
alt="a cool image"
layout="responsive"
/>
) : (
<img width="300" height="300" src="/my-img.jpg" alt="a cool image" />
)}
</div>
)
}
export default About
The page above is a hybrid AMP page, which means:
* The page is rendered as traditional HTML (default) and AMP HTML (by adding `?amp=1` to the URL)
* The AMP version of the page only has valid optimizations applied with AMP Optimizer so that it is indexable by search-engines
The page uses `useAmp` to differentiate between modes, it's a [React Hook](https://react.dev/reference/react) that returns `true` if the page is using AMP, and `false` otherwise.
[Previous
NextResponse
](/docs/pages/api-reference/functions/next-response)
[Next
useReportWebVitals
](/docs/pages/api-reference/functions/use-report-web-vitals)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"01e81f5507b0db2c614668f09bc2da83\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/get-server-side-props | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [
getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Context parameter](#context-parameter)
* [getServerSideProps return values](#getserversideprops-return-values)
* [props](#props)
* [notFound](#notfound)
* [redirect](#redirect)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/get-server-side-props.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)getServerSideProps
getServerSideProps
==================
When exporting a function called `getServerSideProps` (Server-Side Rendering) from a page, Next.js will pre-render this page on each request using the data returned by `getServerSideProps`. This is useful if you want to fetch data that changes often, and have the page update to show the most current data.
pages/index.tsx
TypeScript
JavaScriptTypeScript
import type { InferGetServerSidePropsType, GetServerSideProps } from 'next'
type Repo = {
name: string
stargazers_count: number
}
export const getServerSideProps = (async () => {
// Fetch data from external API
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo: Repo = await res.json()
// Pass data to the page via props
return { props: { repo } }
}) satisfies GetServerSideProps<{ repo: Repo }>
export default function Page({
repo,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<main>
<p>{repo.stargazers_count}</p>
</main>
)
}
You can import modules in top-level scope for use in `getServerSideProps`. Imports used will **not be bundled for the client-side**. This means you can write **server-side code directly in `getServerSideProps`**, including fetching data from your database.
[Context parameter](#context-parameter)
---------------------------------------
The `context` parameter is an object containing the following keys:
Name
Description
`params`
If this page uses a [dynamic route](/docs/pages/building-your-application/routing/dynamic-routes), `params` contains the route parameters. If the page name is `[id].js`, then `params` will look like `{ id: ... }`.
`req`
[The `HTTP` IncomingMessage object](https://nodejs.org/api/http.html#http_class_http_incomingmessage), with an additional `cookies` prop, which is an object with string keys mapping to string values of cookies.
`res`
[The `HTTP` response object](https://nodejs.org/api/http.html#http_class_http_serverresponse).
`query`
An object representing the query string, including dynamic route parameters.
`preview`
(Deprecated for `draftMode`) `preview` is `true` if the page is in the [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode) and `false` otherwise.
`previewData`
(Deprecated for `draftMode`) The [preview](/docs/pages/building-your-application/configuring/preview-mode) data set by `setPreviewData`.
`draftMode`
`draftMode` is `true` if the page is in the [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode) and `false` otherwise.
`resolvedUrl`
A normalized version of the request `URL` that strips the `_next/data` prefix for client transitions and includes original query values.
`locale`
Contains the active locale (if enabled).
`locales`
Contains all supported locales (if enabled).
`defaultLocale`
Contains the configured default locale (if enabled).
[getServerSideProps return values](#getserversideprops-return-values)
---------------------------------------------------------------------
The `getServerSideProps` function should return an object with **any one of the following** properties:
### [`props`](#props)
The `props` object is a key-value pair, where each value is received by the page component. It should be a [serializable object](https://developer.mozilla.org/docs/Glossary/Serialization) so that any props passed, could be serialized with [`JSON.stringify`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
export async function getServerSideProps(context) {
return {
props: { message: `Next.js is awesome` }, // will be passed to the page component as props
}
}
### [`notFound`](#notfound)
The `notFound` boolean allows the page to return a `404` status and [404 Page](/docs/pages/building-your-application/routing/custom-error#404-page). With `notFound: true`, the page will return a `404` even if there was a successfully generated page before. This is meant to support use cases like user-generated content getting removed by its author.
export async function getServerSideProps(context) {
const res = await fetch(`https://.../data`)
const data = await res.json()
if (!data) {
return {
notFound: true,
}
}
return {
props: { data }, // will be passed to the page component as props
}
}
### [`redirect`](#redirect)
The `redirect` object allows redirecting to internal and external resources. It should match the shape of `{ destination: string, permanent: boolean }`. In some rare cases, you might need to assign a custom status code for older `HTTP` clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both.
export async function getServerSideProps(context) {
const res = await fetch(`https://.../data`)
const data = await res.json()
if (!data) {
return {
redirect: {
destination: '/',
permanent: false,
},
}
}
return {
props: {}, // will be passed to the page component as props
}
}
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.4.0`
[App Router](/docs/app/building-your-application/data-fetching) is now stable with simplified data fetching
`v10.0.0`
`locale`, `locales`, `defaultLocale`, and `notFound` options added.
`v9.3.0`
`getServerSideProps` introduced.
[Previous
getInitialProps
](/docs/pages/api-reference/functions/get-initial-props)
[Next
getStaticPaths
](/docs/pages/api-reference/functions/get-static-paths)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"857583d16ae72be6decd065dfc059dac\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/use-report-web-vitals | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [
useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [useReportWebVitals](#usereportwebvitals)
* [Web Vitals](#web-vitals)
* [Custom Metrics](#custom-metrics)
* [Usage on Vercel](#usage-on-vercel)
* [Sending results to external systems](#sending-results-to-external-systems)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/use-report-web-vitals.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)useReportWebVitals
useReportWebVitals
==================
The `useReportWebVitals` hook allows you to report [Core Web Vitals](https://web.dev/vitals/), and can be used in combination with your analytics service.
pages/\_app.js
import { useReportWebVitals } from 'next/web-vitals'
function MyApp({ Component, pageProps }) {
useReportWebVitals((metric) => {
console.log(metric)
})
return <Component {...pageProps} />
}
[useReportWebVitals](#usereportwebvitals)
-----------------------------------------
The `metric` object passed as the hook's argument consists of a number of properties:
* `id`: Unique identifier for the metric in the context of the current page load
* `name`: The name of the performance metric. Possible values include names of [Web Vitals](#web-vitals) metrics (TTFB, FCP, LCP, FID, CLS) specific to a web application.
* `delta`: The difference between the current value and the previous value of the metric. The value is typically in milliseconds and represents the change in the metric's value over time.
* `entries`: An array of [Performance Entries](https://developer.mozilla.org/docs/Web/API/PerformanceEntry) associated with the metric. These entries provide detailed information about the performance events related to the metric.
* `navigationType`: Indicates the [type of navigation](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming/type) that triggered the metric collection. Possible values include `"navigate"`, `"reload"`, `"back_forward"`, and `"prerender"`.
* `rating`: A qualitative rating of the metric value, providing an assessment of the performance. Possible values are `"good"`, `"needs-improvement"`, and `"poor"`. The rating is typically determined by comparing the metric value against predefined thresholds that indicate acceptable or suboptimal performance.
* `value`: The actual value or duration of the performance entry, typically in milliseconds. The value provides a quantitative measure of the performance aspect being tracked by the metric. The source of the value depends on the specific metric being measured and can come from various [Performance API](https://developer.mozilla.org/docs/Web/API/Performance_API)s.
[Web Vitals](#web-vitals)
-------------------------
[Web Vitals](https://web.dev/vitals/) are a set of useful metrics that aim to capture the user experience of a web page. The following web vitals are all included:
* [Time to First Byte](https://developer.mozilla.org/docs/Glossary/Time_to_first_byte) (TTFB)
* [First Contentful Paint](https://developer.mozilla.org/docs/Glossary/First_contentful_paint) (FCP)
* [Largest Contentful Paint](https://web.dev/lcp/) (LCP)
* [First Input Delay](https://web.dev/fid/) (FID)
* [Cumulative Layout Shift](https://web.dev/cls/) (CLS)
* [Interaction to Next Paint](https://web.dev/inp/) (INP)
You can handle all the results of these metrics using the `name` property.
pages/\_app.js
import { useReportWebVitals } from 'next/web-vitals'
function MyApp({ Component, pageProps }) {
useReportWebVitals((metric) => {
switch (metric.name) {
case 'FCP': {
// handle FCP results
}
case 'LCP': {
// handle LCP results
}
// ...
}
})
return <Component {...pageProps} />
}
[Custom Metrics](#custom-metrics)
---------------------------------
In addition to the core metrics listed above, there are some additional custom metrics that measure the time it takes for the page to hydrate and render:
* `Next.js-hydration`: Length of time it takes for the page to start and finish hydrating (in ms)
* `Next.js-route-change-to-render`: Length of time it takes for a page to start rendering after a route change (in ms)
* `Next.js-render`: Length of time it takes for a page to finish render after a route change (in ms)
You can handle all the results of these metrics separately:
pages/\_app.js
import { useReportWebVitals } from 'next/web-vitals'
function MyApp({ Component, pageProps }) {
useReportWebVitals((metric) => {
switch (metric.name) {
case 'Next.js-hydration':
// handle hydration results
break
case 'Next.js-route-change-to-render':
// handle route-change to render results
break
case 'Next.js-render':
// handle render results
break
default:
break
}
})
return <Component {...pageProps} />
}
These metrics work in all browsers that support the [User Timing API](https://caniuse.com/#feat=user-timing).
[Usage on Vercel](#usage-on-vercel)
-----------------------------------
[Vercel Speed Insights](https://vercel.com/docs/concepts/speed-insights) are automatically configured on Vercel deployments, and don't require the use of `useReportWebVitals`. This hook is useful in local development, or if you're using a different analytics service.
[Sending results to external systems](#sending-results-to-external-systems)
---------------------------------------------------------------------------
You can send results to any endpoint to measure and track real user performance on your site. For example:
useReportWebVitals((metric) => {
const body = JSON.stringify(metric)
const url = 'https://example.com/analytics'
// Use `navigator.sendBeacon()` if available, falling back to `fetch()`.
if (navigator.sendBeacon) {
navigator.sendBeacon(url, body)
} else {
fetch(url, { body, method: 'POST', keepalive: true })
}
})
> **Good to know**: If you use [Google Analytics](https://analytics.google.com/analytics/web/), using the `id` value can allow you to construct metric distributions manually (to calculate percentiles, etc.)
> useReportWebVitals(metric => {
> // Use `window.gtag` if you initialized Google Analytics as this example:
> // https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics/pages/_app.js
> window.gtag('event', metric.name, {
> value: Math.round(metric.name === 'CLS' ? metric.value * 1000 : metric.value), // values must be integers
> event_label: metric.id, // id unique to current page load
> non_interaction: true, // avoids affecting bounce rate.
> });
> }
>
> Read more about [sending results to Google Analytics](https://github.com/GoogleChrome/web-vitals#send-the-results-to-google-analytics).
[Previous
useAmp
](/docs/pages/api-reference/functions/use-amp)
[Next
useRouter
](/docs/pages/api-reference/functions/use-router)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f5fdc907a70577fe773a216d9b9b8126\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/typescript | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [
typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/typescript.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)typescript
typescript
==========
Next.js fails your **production build** (`next build`) when TypeScript errors are present in your project.
If you'd like Next.js to dangerously produce production code even when your application has errors, you can disable the built-in type checking step.
If disabled, be sure you are running type checks as part of your build or deploy process, otherwise this can be very dangerous.
Open `next.config.js` and enable the `ignoreBuildErrors` option in the `typescript` config:
next.config.js
module.exports = {
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
}
[Previous
turbo
](/docs/pages/api-reference/next-config-js/turbo)
[Next
urlImports
](/docs/pages/api-reference/next-config-js/urlImports)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"4d1eeceffed0e9122071b7d8efd4476f\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/get-static-props | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [
getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Context parameter](#context-parameter)
* [getStaticProps return values](#getstaticprops-return-values)
* [props](#props)
* [revalidate](#revalidate)
* [notFound](#notfound)
* [redirect](#redirect)
* [Reading files: Use process.cwd()](#reading-files-use-processcwd)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/get-static-props.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)getStaticProps
getStaticProps
==============
Exporting a function called `getStaticProps` will pre-render a page at build time using the props returned from the function:
pages/index.tsx
TypeScript
JavaScriptTypeScript
import type { InferGetStaticPropsType, GetStaticProps } from 'next'
type Repo = {
name: string
stargazers_count: number
}
export const getStaticProps = (async (context) => {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = await res.json()
return { props: { repo } }
}) satisfies GetStaticProps<{
repo: Repo
}>
export default function Page({
repo,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return repo.stargazers_count
}
You can import modules in top-level scope for use in `getStaticProps`. Imports used will **not be bundled for the client-side**. This means you can write **server-side code directly in `getStaticProps`**, including fetching data from your database.
[Context parameter](#context-parameter)
---------------------------------------
The `context` parameter is an object containing the following keys:
Name
Description
`params`
Contains the route parameters for pages using [dynamic routes](/docs/pages/building-your-application/routing/dynamic-routes). For example, if the page name is `[id].js`, then `params` will look like `{ id: ... }`. You should use this together with `getStaticPaths`, which we'll explain later.
`preview`
(Deprecated for `draftMode`) `preview` is `true` if the page is in the [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode) and `false` otherwise.
`previewData`
(Deprecated for `draftMode`) The [preview](/docs/pages/building-your-application/configuring/preview-mode) data set by `setPreviewData`.
`draftMode`
`draftMode` is `true` if the page is in the [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode) and `false` otherwise.
`locale`
Contains the active locale (if enabled).
`locales`
Contains all supported locales (if enabled).
`defaultLocale`
Contains the configured default locale (if enabled).
`revalidateReason`
Provides a reason for why the function was called. Can be one of: "build" (run at build time), "stale" (revalidate period expired, or running in [development mode](/docs/pages/building-your-application/data-fetching/get-static-props#runs-on-every-request-in-development)), "on-demand" (triggered via [on-demand revalidation](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation))
[getStaticProps return values](#getstaticprops-return-values)
-------------------------------------------------------------
The `getStaticProps` function should return an object containing either `props`, `redirect`, or `notFound` followed by an **optional** `revalidate` property.
### [`props`](#props)
The `props` object is a key-value pair, where each value is received by the page component. It should be a [serializable object](https://developer.mozilla.org/docs/Glossary/Serialization) so that any props passed, could be serialized with [`JSON.stringify`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
export async function getStaticProps(context) {
return {
props: { message: `Next.js is awesome` }, // will be passed to the page component as props
}
}
### [`revalidate`](#revalidate)
The `revalidate` property is the amount in seconds after which a page re-generation can occur (defaults to `false` or no revalidation).
// This function gets called at build time on server-side.
// It may be called again, on a serverless function, if
// revalidation is enabled and a new request comes in
export async function getStaticProps() {
const res = await fetch('https://.../posts')
const posts = await res.json()
return {
props: {
posts,
},
// Next.js will attempt to re-generate the page:
// - When a request comes in
// - At most once every 10 seconds
revalidate: 10, // In seconds
}
}
Learn more about [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration).
The cache status of a page leveraging ISR can be determined by reading the value of the `x-nextjs-cache` response header. The possible values are the following:
* `MISS` - the path is not in the cache (occurs at most once, on the first visit)
* `STALE` - the path is in the cache but exceeded the revalidate time so it will be updated in the background
* `HIT` - the path is in the cache and has not exceeded the revalidate time
### [`notFound`](#notfound)
The `notFound` boolean allows the page to return a `404` status and [404 Page](/docs/pages/building-your-application/routing/custom-error#404-page). With `notFound: true`, the page will return a `404` even if there was a successfully generated page before. This is meant to support use cases like user-generated content getting removed by its author. Note, `notFound` follows the same `revalidate` behavior [described here](#revalidate).
export async function getStaticProps(context) {
const res = await fetch(`https://.../data`)
const data = await res.json()
if (!data) {
return {
notFound: true,
}
}
return {
props: { data }, // will be passed to the page component as props
}
}
> **Good to know**: `notFound` is not needed for [`fallback: false`](/docs/pages/api-reference/functions/get-static-paths#fallback-false) mode as only paths returned from `getStaticPaths` will be pre-rendered.
### [`redirect`](#redirect)
The `redirect` object allows redirecting to internal or external resources. It should match the shape of `{ destination: string, permanent: boolean }`.
In some rare cases, you might need to assign a custom status code for older `HTTP` clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, **but not both**. You can also set `basePath: false` similar to redirects in `next.config.js`.
export async function getStaticProps(context) {
const res = await fetch(`https://...`)
const data = await res.json()
if (!data) {
return {
redirect: {
destination: '/',
permanent: false,
// statusCode: 301
},
}
}
return {
props: { data }, // will be passed to the page component as props
}
}
If the redirects are known at build-time, they should be added in [`next.config.js`](/docs/pages/api-reference/next-config-js/redirects) instead.
[Reading files: Use `process.cwd()`](#reading-files-use-processcwd)
-------------------------------------------------------------------
Files can be read directly from the filesystem in `getStaticProps`.
In order to do so you have to get the full path to a file.
Since Next.js compiles your code into a separate directory you can't use `__dirname` as the path it returns will be different from the Pages Router.
Instead you can use `process.cwd()` which gives you the directory where Next.js is being executed.
import { promises as fs } from 'fs'
import path from 'path'
// posts will be populated at build time by getStaticProps()
function Blog({ posts }) {
return (
<ul>
{posts.map((post) => (
<li>
<h3>{post.filename}</h3>
<p>{post.content}</p>
</li>
))}
</ul>
)
}
// This function gets called at build time on server-side.
// It won't be called on client-side, so you can even do
// direct database queries.
export async function getStaticProps() {
const postsDirectory = path.join(process.cwd(), 'posts')
const filenames = await fs.readdir(postsDirectory)
const posts = filenames.map(async (filename) => {
const filePath = path.join(postsDirectory, filename)
const fileContents = await fs.readFile(filePath, 'utf8')
// Generally you would parse/transform the contents
// For example you can transform markdown to HTML here
return {
filename,
content: fileContents,
}
})
// By returning { props: { posts } }, the Blog component
// will receive `posts` as a prop at build time
return {
props: {
posts: await Promise.all(posts),
},
}
}
export default Blog
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.4.0`
[App Router](/docs/app/building-your-application/data-fetching) is now stable with simplified data fetching
`v12.2.0`
[On-Demand Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation) is stable.
`v12.1.0`
[On-Demand Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation) added (beta).
`v10.0.0`
`locale`, `locales`, `defaultLocale`, and `notFound` options added.
`v10.0.0`
`fallback: 'blocking'` return option added.
`v9.5.0`
Stable [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
`v9.3.0`
`getStaticProps` introduced.
[Previous
getStaticPaths
](/docs/pages/api-reference/functions/get-static-paths)
[Next
NextRequest
](/docs/pages/api-reference/functions/next-request)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"775a16367526b50e68be5572e35f7f57\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/use-router | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [
useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [router object](#router-object)
* [router.push](#routerpush)
* [Resetting state after navigation](#resetting-state-after-navigation)
* [With URL object](#with-url-object)
* [router.replace](#routerreplace)
* [router.prefetch](#routerprefetch)
* [router.beforePopState](#routerbeforepopstate)
* [router.back](#routerback)
* [router.reload](#routerreload)
* [router.events](#routerevents)
* [Potential ESLint errors](#potential-eslint-errors)
* [Potential solutions](#potential-solutions)
* [withRouter](#withrouter)
* [Usage](#usage)
* [TypeScript](#typescript)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/use-router.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)useRouter
useRouter
=========
If you want to access the [`router` object](#router-object) inside any function component in your app, you can use the `useRouter` hook, take a look at the following example:
import { useRouter } from 'next/router'
function ActiveLink({ children, href }) {
const router = useRouter()
const style = {
marginRight: 10,
color: router.asPath === href ? 'red' : 'black',
}
const handleClick = (e) => {
e.preventDefault()
router.push(href)
}
return (
<a href={href} onClick={handleClick} style={style}>
{children}
</a>
)
}
export default ActiveLink
> `useRouter` is a [React Hook](https://react.dev/learn#using-hooks), meaning it cannot be used with classes. You can either use [withRouter](#withrouter) or wrap your class in a function component.
[`router` object](#router-object)
---------------------------------
The following is the definition of the `router` object returned by both [`useRouter`](#top) and [`withRouter`](#withrouter):
* `pathname`: `String` - The path for current route file that comes after `/pages`. Therefore, `basePath`, `locale` and trailing slash (`trailingSlash: true`) are not included.
* `query`: `Object` - The query string parsed to an object, including [dynamic route](/docs/pages/building-your-application/routing/dynamic-routes) parameters. It will be an empty object during prerendering if the page doesn't use [Server-side Rendering](/docs/pages/building-your-application/data-fetching/get-server-side-props). Defaults to `{}`
* `asPath`: `String` - The path as shown in the browser including the search params and respecting the `trailingSlash` configuration. `basePath` and `locale` are not included.
* `isFallback`: `boolean` - Whether the current page is in [fallback mode](/docs/pages/api-reference/functions/get-static-paths#fallback-true).
* `basePath`: `String` - The active [basePath](/docs/app/api-reference/next-config-js/basePath) (if enabled).
* `locale`: `String` - The active locale (if enabled).
* `locales`: `String[]` - All supported locales (if enabled).
* `defaultLocale`: `String` - The current default locale (if enabled).
* `domainLocales`: `Array<{domain, defaultLocale, locales}>` - Any configured domain locales.
* `isReady`: `boolean` - Whether the router fields are updated client-side and ready for use. Should only be used inside of `useEffect` methods and not for conditionally rendering on the server. See related docs for use case with [automatically statically optimized pages](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* `isPreview`: `boolean` - Whether the application is currently in [preview mode](/docs/pages/building-your-application/configuring/preview-mode).
> Using the `asPath` field may lead to a mismatch between client and server if the page is rendered using server-side rendering or [automatic static optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization). Avoid using `asPath` until the `isReady` field is `true`.
The following methods are included inside `router`:
### [router.push](#routerpush)
Handles client-side transitions, this method is useful for cases where [`next/link`](/docs/pages/api-reference/components/link) is not enough.
router.push(url, as, options)
* `url`: `UrlObject | String` - The URL to navigate to (see [Node.JS URL module documentation](https://nodejs.org/api/url.html#legacy-urlobject) for `UrlObject` properties).
* `as`: `UrlObject | String` - Optional decorator for the path that will be shown in the browser URL bar. Before Next.js 9.5.3 this was used for dynamic routes.
* `options` - Optional object with the following configuration options:
* `scroll` - Optional boolean, controls scrolling to the top of the page after navigation. Defaults to `true`
* [`shallow`](/docs/pages/building-your-application/routing/linking-and-navigating#shallow-routing): Update the path of the current page without rerunning [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props), [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) or [`getInitialProps`](/docs/pages/api-reference/functions/get-initial-props). Defaults to `false`
* `locale` - Optional string, indicates locale of the new page
> You don't need to use `router.push` for external URLs. [window.location](https://developer.mozilla.org/docs/Web/API/Window/location) is better suited for those cases.
Navigating to `pages/about.js`, which is a predefined route:
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.push('/about')}>
Click me
</button>
)
}
Navigating `pages/post/[pid].js`, which is a dynamic route:
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.push('/post/abc')}>
Click me
</button>
)
}
Redirecting the user to `pages/login.js`, useful for pages behind [authentication](/docs/pages/building-your-application/authentication):
import { useEffect } from 'react'
import { useRouter } from 'next/router'
// Here you would fetch and return the user
const useUser = () => ({ user: null, loading: false })
export default function Page() {
const { user, loading } = useUser()
const router = useRouter()
useEffect(() => {
if (!(user || loading)) {
router.push('/login')
}
}, [user, loading])
return <p>Redirecting...</p>
}
#### [Resetting state after navigation](#resetting-state-after-navigation)
When navigating to the same page in Next.js, the page's state **will not** be reset by default as React does not unmount unless the parent component has changed.
pages/\[slug\].js
import Link from 'next/link'
import { useState } from 'react'
import { useRouter } from 'next/router'
export default function Page(props) {
const router = useRouter()
const [count, setCount] = useState(0)
return (
<div>
<h1>Page: {router.query.slug}</h1>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increase count</button>
<Link href="/one">one</Link> <Link href="/two">two</Link>
</div>
)
}
In the above example, navigating between `/one` and `/two` **will not** reset the count . The `useState` is maintained between renders because the top-level React component, `Page`, is the same.
If you do not want this behavior, you have a couple of options:
* Manually ensure each state is updated using `useEffect`. In the above example, that could look like:
useEffect(() => {
setCount(0)
}, [router.query.slug])
* Use a React `key` to [tell React to remount the component](https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key). To do this for all pages, you can use a custom app:
pages/\_app.js
import { useRouter } from 'next/router'
export default function MyApp({ Component, pageProps }) {
const router = useRouter()
return <Component key={router.asPath} {...pageProps} />
}
#### [With URL object](#with-url-object)
You can use a URL object in the same way you can use it for [`next/link`](/docs/pages/api-reference/components/link#with-url-object). Works for both the `url` and `as` parameters:
import { useRouter } from 'next/router'
export default function ReadMore({ post }) {
const router = useRouter()
return (
<button
type="button"
onClick={() => {
router.push({
pathname: '/post/[pid]',
query: { pid: post.id },
})
}}
>
Click here to read more
</button>
)
}
### [router.replace](#routerreplace)
Similar to the `replace` prop in [`next/link`](/docs/pages/api-reference/components/link), `router.replace` will prevent adding a new URL entry into the `history` stack.
router.replace(url, as, options)
* The API for `router.replace` is exactly the same as the API for [`router.push`](#routerpush).
Take a look at the following example:
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.replace('/home')}>
Click me
</button>
)
}
### [router.prefetch](#routerprefetch)
Prefetch pages for faster client-side transitions. This method is only useful for navigations without [`next/link`](/docs/pages/api-reference/components/link), as `next/link` takes care of prefetching pages automatically.
> This is a production only feature. Next.js doesn't prefetch pages in development.
router.prefetch(url, as, options)
* `url` - The URL to prefetch, including explicit routes (e.g. `/dashboard`) and dynamic routes (e.g. `/product/[id]`)
* `as` - Optional decorator for `url`. Before Next.js 9.5.3 this was used to prefetch dynamic routes.
* `options` - Optional object with the following allowed fields:
* `locale` - allows providing a different locale from the active one. If `false`, `url` has to include the locale as the active locale won't be used.
Let's say you have a login page, and after a login, you redirect the user to the dashboard. For that case, we can prefetch the dashboard to make a faster transition, like in the following example:
import { useCallback, useEffect } from 'react'
import { useRouter } from 'next/router'
export default function Login() {
const router = useRouter()
const handleSubmit = useCallback((e) => {
e.preventDefault()
fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
/* Form data */
}),
}).then((res) => {
// Do a fast client-side transition to the already prefetched dashboard page
if (res.ok) router.push('/dashboard')
})
}, [])
useEffect(() => {
// Prefetch the dashboard page
router.prefetch('/dashboard')
}, [router])
return (
<form onSubmit={handleSubmit}>
{/* Form fields */}
<button type="submit">Login</button>
</form>
)
}
### [router.beforePopState](#routerbeforepopstate)
In some cases (for example, if using a [Custom Server](/docs/pages/building-your-application/configuring/custom-server)), you may wish to listen to [popstate](https://developer.mozilla.org/docs/Web/Events/popstate) and do something before the router acts on it.
router.beforePopState(cb)
* `cb` - The function to run on incoming `popstate` events. The function receives the state of the event as an object with the following props:
* `url`: `String` - the route for the new state. This is usually the name of a `page`
* `as`: `String` - the url that will be shown in the browser
* `options`: `Object` - Additional options sent by [router.push](#routerpush)
If `cb` returns `false`, the Next.js router will not handle `popstate`, and you'll be responsible for handling it in that case. See [Disabling file-system routing](/docs/pages/building-your-application/configuring/custom-server#disabling-file-system-routing).
You could use `beforePopState` to manipulate the request, or force a SSR refresh, as in the following example:
import { useEffect } from 'react'
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
useEffect(() => {
router.beforePopState(({ url, as, options }) => {
// I only want to allow these two routes!
if (as !== '/' && as !== '/other') {
// Have SSR render bad routes as a 404.
window.location.href = as
return false
}
return true
})
}, [router])
return <p>Welcome to the page</p>
}
### [router.back](#routerback)
Navigate back in history. Equivalent to clicking the browser’s back button. It executes `window.history.back()`.
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.back()}>
Click here to go back
</button>
)
}
### [router.reload](#routerreload)
Reload the current URL. Equivalent to clicking the browser’s refresh button. It executes `window.location.reload()`.
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.reload()}>
Click here to reload
</button>
)
}
### [router.events](#routerevents)
You can listen to different events happening inside the Next.js Router. Here's a list of supported events:
* `routeChangeStart(url, { shallow })` - Fires when a route starts to change
* `routeChangeComplete(url, { shallow })` - Fires when a route changed completely
* `routeChangeError(err, url, { shallow })` - Fires when there's an error when changing routes, or a route load is cancelled
* `err.cancelled` - Indicates if the navigation was cancelled
* `beforeHistoryChange(url, { shallow })` - Fires before changing the browser's history
* `hashChangeStart(url, { shallow })` - Fires when the hash will change but not the page
* `hashChangeComplete(url, { shallow })` - Fires when the hash has changed but not the page
> **Good to know**: Here `url` is the URL shown in the browser, including the [`basePath`](/docs/app/api-reference/next-config-js/basePath).
For example, to listen to the router event `routeChangeStart`, open or create `pages/_app.js` and subscribe to the event, like so:
import { useEffect } from 'react'
import { useRouter } from 'next/router'
export default function MyApp({ Component, pageProps }) {
const router = useRouter()
useEffect(() => {
const handleRouteChange = (url, { shallow }) => {
console.log(
`App is changing to ${url} ${
shallow ? 'with' : 'without'
} shallow routing`
)
}
router.events.on('routeChangeStart', handleRouteChange)
// If the component is unmounted, unsubscribe
// from the event with the `off` method:
return () => {
router.events.off('routeChangeStart', handleRouteChange)
}
}, [router])
return <Component {...pageProps} />
}
> We use a [Custom App](/docs/pages/building-your-application/routing/custom-app) (`pages/_app.js`) for this example to subscribe to the event because it's not unmounted on page navigations, but you can subscribe to router events on any component in your application.
Router events should be registered when a component mounts ([useEffect](https://react.dev/reference/react/useEffect) or [componentDidMount](https://react.dev/reference/react/Component#componentdidmount) / [componentWillUnmount](https://react.dev/reference/react/Component#componentwillunmount)) or imperatively when an event happens.
If a route load is cancelled (for example, by clicking two links rapidly in succession), `routeChangeError` will fire. And the passed `err` will contain a `cancelled` property set to `true`, as in the following example:
import { useEffect } from 'react'
import { useRouter } from 'next/router'
export default function MyApp({ Component, pageProps }) {
const router = useRouter()
useEffect(() => {
const handleRouteChangeError = (err, url) => {
if (err.cancelled) {
console.log(`Route to ${url} was cancelled!`)
}
}
router.events.on('routeChangeError', handleRouteChangeError)
// If the component is unmounted, unsubscribe
// from the event with the `off` method:
return () => {
router.events.off('routeChangeError', handleRouteChangeError)
}
}, [router])
return <Component {...pageProps} />
}
[Potential ESLint errors](#potential-eslint-errors)
---------------------------------------------------
Certain methods accessible on the `router` object return a Promise. If you have the ESLint rule, [no-floating-promises](https://typescript-eslint.io/rules/no-floating-promises) enabled, consider disabling it either globally, or for the affected line.
If your application needs this rule, you should either `void` the promise – or use an `async` function, `await` the Promise, then void the function call. **This is not applicable when the method is called from inside an `onClick` handler**.
The affected methods are:
* `router.push`
* `router.replace`
* `router.prefetch`
### [Potential solutions](#potential-solutions)
import { useEffect } from 'react'
import { useRouter } from 'next/router'
// Here you would fetch and return the user
const useUser = () => ({ user: null, loading: false })
export default function Page() {
const { user, loading } = useUser()
const router = useRouter()
useEffect(() => {
// disable the linting on the next line - This is the cleanest solution
// eslint-disable-next-line no-floating-promises
router.push('/login')
// void the Promise returned by router.push
if (!(user || loading)) {
void router.push('/login')
}
// or use an async function, await the Promise, then void the function call
async function handleRouteChange() {
if (!(user || loading)) {
await router.push('/login')
}
}
void handleRouteChange()
}, [user, loading])
return <p>Redirecting...</p>
}
[withRouter](#withrouter)
-------------------------
If [`useRouter`](#router-object) is not the best fit for you, `withRouter` can also add the same [`router` object](#router-object) to any component.
### [Usage](#usage)
import { withRouter } from 'next/router'
function Page({ router }) {
return <p>{router.pathname}</p>
}
export default withRouter(Page)
### [TypeScript](#typescript)
To use class components with `withRouter`, the component needs to accept a router prop:
import React from 'react'
import { withRouter, NextRouter } from 'next/router'
interface WithRouterProps {
router: NextRouter
}
interface MyComponentProps extends WithRouterProps {}
class MyComponent extends React.Component<MyComponentProps> {
render() {
return <p>{this.props.router.pathname}</p>
}
}
export default withRouter(MyComponent)
[Previous
useReportWebVitals
](/docs/pages/api-reference/functions/use-report-web-vitals)
[Next
userAgent
](/docs/pages/api-reference/functions/userAgent)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"2229083fafaf36abe971285e9eacba31\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/next-response | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [
NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [cookies](#cookies)
* [set(name, value)](#setname-value)
* [get(name)](#getname)
* [getAll()](#getall)
* [delete(name)](#deletename)
* [json()](#json)
* [redirect()](#redirect)
* [rewrite()](#rewrite)
* [next()](#next)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/next-response.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)NextResponse
NextResponse
============
NextResponse extends the [Web Response API](https://developer.mozilla.org/docs/Web/API/Response) with additional convenience methods.
[`cookies`](#cookies)
---------------------
Read or mutate the [`Set-Cookie`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie) header of the response.
### [`set(name, value)`](#setname-value)
Given a name, set a cookie with the given value on the response.
// Given incoming request /home
let response = NextResponse.next()
// Set a cookie to hide the banner
response.cookies.set('show-banner', 'false')
// Response will have a `Set-Cookie:show-banner=false;path=/home` header
return response
### [`get(name)`](#getname)
Given a cookie name, return the value of the cookie. If the cookie is not found, `undefined` is returned. If multiple cookies are found, the first one is returned.
// Given incoming request /home
let response = NextResponse.next()
// { name: 'show-banner', value: 'false', Path: '/home' }
response.cookies.get('show-banner')
### [`getAll()`](#getall)
Given a cookie name, return the values of the cookie. If no name is given, return all cookies on the response.
// Given incoming request /home
let response = NextResponse.next()
// [
// { name: 'experiments', value: 'new-pricing-page', Path: '/home' },
// { name: 'experiments', value: 'winter-launch', Path: '/home' },
// ]
response.cookies.getAll('experiments')
// Alternatively, get all cookies for the response
response.cookies.getAll()
### [`delete(name)`](#deletename)
Given a cookie name, delete the cookie from the response.
// Given incoming request /home
let response = NextResponse.next()
// Returns true for deleted, false is nothing is deleted
response.cookies.delete('experiments')
[`json()`](#json)
-----------------
Produce a response with the given JSON body.
app/api/route.ts
TypeScript
JavaScriptTypeScript
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
}
[`redirect()`](#redirect)
-------------------------
Produce a response that redirects to a [URL](https://developer.mozilla.org/docs/Web/API/URL).
import { NextResponse } from 'next/server'
return NextResponse.redirect(new URL('/new', request.url))
The [URL](https://developer.mozilla.org/docs/Web/API/URL) can be created and modified before being used in the `NextResponse.redirect()` method. For example, you can use the `request.nextUrl` property to get the current URL, and then modify it to redirect to a different URL.
import { NextResponse } from 'next/server'
// Given an incoming request...
const loginUrl = new URL('/login', request.url)
// Add ?from=/incoming-url to the /login URL
loginUrl.searchParams.set('from', request.nextUrl.pathname)
// And redirect to the new URL
return NextResponse.redirect(loginUrl)
[`rewrite()`](#rewrite)
-----------------------
Produce a response that rewrites (proxies) the given [URL](https://developer.mozilla.org/docs/Web/API/URL) while preserving the original URL.
import { NextResponse } from 'next/server'
// Incoming request: /about, browser shows /about
// Rewritten request: /proxy, browser shows /about
return NextResponse.rewrite(new URL('/proxy', request.url))
[`next()`](#next)
-----------------
The `next()` method is useful for Middleware, as it allows you to return early and continue routing.
import { NextResponse } from 'next/server'
return NextResponse.next()
You can also forward `headers` when producing the response:
import { NextResponse } from 'next/server'
// Given an incoming request...
const newHeaders = new Headers(request.headers)
// Add a new header
newHeaders.set('x-version', '123')
// And produce a response with the new headers
return NextResponse.next({
request: {
// New request headers
headers: newHeaders,
},
})
[Previous
NextRequest
](/docs/pages/api-reference/functions/next-request)
[Next
useAmp
](/docs/pages/api-reference/functions/use-amp)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"ca7e4447af5dd8a755ec40377b6f6075\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/env | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [
env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/env.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)env
env
===
> Since the release of [Next.js 9.4](https://nextjs.org/blog/next-9-4) we now have a more intuitive and ergonomic experience for [adding environment variables](/docs/pages/building-your-application/configuring/environment-variables). Give it a try!
> **Good to know**: environment variables specified in this way will **always** be included in the JavaScript bundle, prefixing the environment variable name with `NEXT_PUBLIC_` only has an effect when specifying them [through the environment or .env files](/docs/pages/building-your-application/configuring/environment-variables).
To add environment variables to the JavaScript bundle, open `next.config.js` and add the `env` config:
next.config.js
module.exports = {
env: {
customKey: 'my-value',
},
}
Now you can access `process.env.customKey` in your code. For example:
function Page() {
return <h1>The value of customKey is: {process.env.customKey}</h1>
}
export default Page
Next.js will replace `process.env.customKey` with `'my-value'` at build time. Trying to destructure `process.env` variables won't work due to the nature of webpack [DefinePlugin](https://webpack.js.org/plugins/define-plugin/).
For example, the following line:
return <h1>The value of customKey is: {process.env.customKey}</h1>
Will end up being:
return <h1>The value of customKey is: {'my-value'}</h1>
[Previous
distDir
](/docs/pages/api-reference/next-config-js/distDir)
[Next
eslint
](/docs/pages/api-reference/next-config-js/eslint)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"2395ce7592b3588262237cdcf9cafd81\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/userAgent | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [
userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [isBot](#isbot)
* [browser](#browser)
* [device](#device)
* [engine](#engine)
* [os](#os)
* [cpu](#cpu)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/userAgent.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)userAgent
userAgent
=========
The `userAgent` helper extends the [Web Request API](https://developer.mozilla.org/docs/Web/API/Request) with additional properties and methods to interact with the user agent object from the request.
middleware.ts
TypeScript
JavaScriptTypeScript
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function middleware(request: NextRequest) {
const url = request.nextUrl
const { device } = userAgent(request)
const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'
url.searchParams.set('viewport', viewport)
return NextResponse.rewrite(url)
}
[`isBot`](#isbot)
-----------------
A boolean indicating whether the request comes from a known bot.
[`browser`](#browser)
---------------------
An object containing information about the browser used in the request.
* `name`: A string representing the browser's name, or `undefined` if not identifiable.
* `version`: A string representing the browser's version, or `undefined`.
[`device`](#device)
-------------------
An object containing information about the device used in the request.
* `model`: A string representing the model of the device, or `undefined`.
* `type`: A string representing the type of the device, such as `console`, `mobile`, `tablet`, `smarttv`, `wearable`, `embedded`, or `undefined`.
* `vendor`: A string representing the vendor of the device, or `undefined`.
[`engine`](#engine)
-------------------
An object containing information about the browser's engine.
* `name`: A string representing the engine's name. Possible values include: `Amaya`, `Blink`, `EdgeHTML`, `Flow`, `Gecko`, `Goanna`, `iCab`, `KHTML`, `Links`, `Lynx`, `NetFront`, `NetSurf`, `Presto`, `Tasman`, `Trident`, `w3m`, `WebKit` or `undefined`.
* `version`: A string representing the engine's version, or `undefined`.
[`os`](#os)
-----------
An object containing information about the operating system.
* `name`: A string representing the name of the OS, or `undefined`.
* `version`: A string representing the version of the OS, or `undefined`.
[`cpu`](#cpu)
-------------
An object containing information about the CPU architecture.
* `architecture`: A string representing the architecture of the CPU. Possible values include: `68k`, `amd64`, `arm`, `arm64`, `armhf`, `avr`, `ia32`, `ia64`, `irix`, `irix64`, `mips`, `mips64`, `pa-risc`, `ppc`, `sparc`, `sparc64` or `undefined`
[Previous
useRouter
](/docs/pages/api-reference/functions/use-router)
[Next
next.config.js Options
](/docs/pages/api-reference/next-config-js)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"118c49cc4b24c728ad7b85153c9c009c\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/crossOrigin | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [
crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Options](#options)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/crossOrigin.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)crossOrigin
crossOrigin
===========
Use the `crossOrigin` option to add a [`crossOrigin` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) in all `<script>` tags generated by the [`next/script`](/docs/pages/building-your-application/optimizing/scripts) and [`next/head`](/docs/pages/api-reference/components/head)components, and define how cross-origin requests should be handled.
next.config.js
module.exports = {
crossOrigin: 'anonymous',
}
[Options](#options)
-------------------
* `'anonymous'`: Adds [`crossOrigin="anonymous"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin#anonymous) attribute.
* `'use-credentials'`: Adds [`crossOrigin="use-credentials"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin#use-credentials).
[Previous
compress
](/docs/pages/api-reference/next-config-js/compress)
[Next
devIndicators
](/docs/pages/api-reference/next-config-js/devIndicators)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"5d9f5bbfdb3342b0c4fec331b71f3b26\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/functions/next-request | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [
NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [cookies](#cookies)
* [set(name, value)](#setname-value)
* [get(name)](#getname)
* [getAll()](#getall)
* [delete(name)](#deletename)
* [has(name)](#hasname)
* [clear()](#clear)
* [nextUrl](#nexturl)
* [ip](#ip)
* [geo](#geo)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/02-functions/next-request.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[Functions](/docs/pages/api-reference/functions)NextRequest
NextRequest
===========
NextRequest extends the [Web Request API](https://developer.mozilla.org/docs/Web/API/Request) with additional convenience methods.
[`cookies`](#cookies)
---------------------
Read or mutate the [`Set-Cookie`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie) header of the request.
### [`set(name, value)`](#setname-value)
Given a name, set a cookie with the given value on the request.
// Given incoming request /home
// Set a cookie to hide the banner
// request will have a `Set-Cookie:show-banner=false;path=/home` header
request.cookies.set('show-banner', 'false')
### [`get(name)`](#getname)
Given a cookie name, return the value of the cookie. If the cookie is not found, `undefined` is returned. If multiple cookies are found, the first one is returned.
// Given incoming request /home
// { name: 'show-banner', value: 'false', Path: '/home' }
request.cookies.get('show-banner')
### [`getAll()`](#getall)
Given a cookie name, return the values of the cookie. If no name is given, return all cookies on the request.
// Given incoming request /home
// [
// { name: 'experiments', value: 'new-pricing-page', Path: '/home' },
// { name: 'experiments', value: 'winter-launch', Path: '/home' },
// ]
request.cookies.getAll('experiments')
// Alternatively, get all cookies for the request
request.cookies.getAll()
### [`delete(name)`](#deletename)
Given a cookie name, delete the cookie from the request.
// Returns true for deleted, false is nothing is deleted
request.cookies.delete('experiments')
### [`has(name)`](#hasname)
Given a cookie name, return `true` if the cookie exists on the request.
// Returns true if cookie exists, false if it does not
request.cookies.has('experiments')
### [`clear()`](#clear)
Remove the `Set-Cookie` header from the request.
request.cookies.clear()
[`nextUrl`](#nexturl)
---------------------
Extends the native [`URL`](https://developer.mozilla.org/docs/Web/API/URL) API with additional convenience methods, including Next.js specific properties.
// Given a request to /home, pathname is /home
request.nextUrl.pathname
// Given a request to /home?name=lee, searchParams is { 'name': 'lee' }
request.nextUrl.searchParams
The following options are available:
Property
Type
Description
`basePath`
`string`
The [base path](/docs/pages/api-reference/next-config-js/basePath) of the URL.
`buildId`
`string` | `undefined`
The build identifier of the Next.js application. Can be [customized](/docs/pages/api-reference/next-config-js/generateBuildId).
`defaultLocale`
`string` | `undefined`
The default locale for [internationalization](/docs/pages/building-your-application/routing/internationalization).
`domainLocale`
\- `defaultLocale`
`string`
The default locale within a domain.
\- `domain`
`string`
The domain associated with a specific locale.
\- `http`
`boolean` | `undefined`
Indicates if the domain is using HTTP.
`locales`
`string[]` | `undefined`
An array of available locales.
`locale`
`string` | `undefined`
The currently active locale.
`url`
`URL`
The URL object.
[`ip`](#ip)
-----------
The `ip` property is a string that contains the IP address of the request. This value can optionally be provided by your hosting platform.
> **Good to know:** On [Vercel](https://vercel.com/docs/frameworks/nextjs?utm_source=next-site&utm_medium=docs&utm_campaign=next-website), this value is provided by default. On other platforms, you can use the [`X-Forwarded-For`](https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Forwarded-For) header to provide the IP address.
// Provided by Vercel
request.ip
// Self-hosting
request.headers.get('X-Forwarded-For')
[`geo`](#geo)
-------------
The `geo` property is an object that contains the geographic information of the request. This value can optionally be provided by your hosting platform.
> **Good to know:** On [Vercel](https://vercel.com/docs/frameworks/nextjs?utm_source=next-site&utm_medium=docs&utm_campaign=next-website), this value is provided by default. On other platforms, you can use the [`X-Forwarded-For`](https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Forwarded-For) header to provide the IP address, then use a [third-party service](https://ip-api.com/) to lookup the geographic information.
// Provided by Vercel
request.geo.city
request.geo.country
request.geo.region
request.geo.latitude
request.geo.longitude
// Self-hosting
function getGeo(request) {
let ip = request.headers.get('X-Forwarded-For')
// Use a third-party service to lookup the geographic information
}
[Previous
getStaticProps
](/docs/pages/api-reference/functions/get-static-props)
[Next
NextResponse
](/docs/pages/api-reference/functions/next-response)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"1684f81c014cb25dc4fdfe4cd75b7a1a\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/assetPrefix | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [
assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/assetPrefix.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)assetPrefix
assetPrefix
===========
> **Attention**: [Deploying to Vercel](/docs/pages/building-your-application/deploying) automatically configures a global CDN for your Next.js project. You do not need to manually setup an Asset Prefix.
> **Good to know**: Next.js 9.5+ added support for a customizable [Base Path](/docs/app/api-reference/next-config-js/basePath), which is better suited for hosting your application on a sub-path like `/docs`. We do not suggest you use a custom Asset Prefix for this use case.
To set up a [CDN](https://en.wikipedia.org/wiki/Content_delivery_network), you can set up an asset prefix and configure your CDN's origin to resolve to the domain that Next.js is hosted on.
Open `next.config.js` and add the `assetPrefix` config:
next.config.js
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
// Use the CDN in production and localhost for development.
assetPrefix: isProd ? 'https://cdn.mydomain.com' : undefined,
}
Next.js will automatically use your asset prefix for the JavaScript and CSS files it loads from the `/_next/` path (`.next/static/` folder). For example, with the above configuration, the following request for a JS chunk:
/_next/static/chunks/4b9b41aaa062cbbfeff4add70f256968c51ece5d.4d708494b3aed70c04f0.js
Would instead become:
https://cdn.mydomain.com/_next/static/chunks/4b9b41aaa062cbbfeff4add70f256968c51ece5d.4d708494b3aed70c04f0.js
The exact configuration for uploading your files to a given CDN will depend on your CDN of choice. The only folder you need to host on your CDN is the contents of `.next/static/`, which should be uploaded as `_next/static/` as the above URL request indicates. **Do not upload the rest of your `.next/` folder**, as you should not expose your server code and other configuration to the public.
While `assetPrefix` covers requests to `_next/static`, it does not influence the following paths:
* Files in the [public](/docs/pages/building-your-application/optimizing/static-assets) folder; if you want to serve those assets over a CDN, you'll have to introduce the prefix yourself
* `/_next/data/` requests for `getServerSideProps` pages. These requests will always be made against the main domain since they're not static.
* `/_next/data/` requests for `getStaticProps` pages. These requests will always be made against the main domain to support [Incremental Static Generation](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration), even if you're not using it (for consistency).
[Previous
next.config.js Options
](/docs/pages/api-reference/next-config-js)
[Next
basePath
](/docs/pages/api-reference/next-config-js/basePath)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"7a81ed9714da4a93a1751cda532a092d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/devIndicators | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [
devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/devIndicators.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)devIndicators
devIndicators
=============
> **Good to know**: This indicator was removed in Next.js version 10.0.1. We recommend upgrading to the latest version of Next.js.
When a page qualifies for [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization) we show an indicator to let you know.
This is helpful since automatic static optimization can be very beneficial and knowing immediately in development if the page qualifies can be useful.
In some cases this indicator might not be useful, like when working on electron applications. To remove it open `next.config.js` and disable the `autoPrerender` config in `devIndicators`:
next.config.js
module.exports = {
devIndicators: {
autoPrerender: false,
},
}
[Previous
crossOrigin
](/docs/pages/api-reference/next-config-js/crossOrigin)
[Next
distDir
](/docs/pages/api-reference/next-config-js/distDir)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"fa370231d42d5bda851e296b04cd9df8\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)next.config.js Options
next.config.js Options
======================
Next.js can be configured through a `next.config.js` file in the root of your project directory (for example, by `package.json`) with a default export.
next.config.js
// @ts-check
/** @type {import('next').NextConfig} */
const nextConfig = {
/* config options here */
}
module.exports = nextConfig
`next.config.js` is a regular Node.js module, not a JSON file. It gets used by the Next.js server and build phases, and it's not included in the browser build.
If you need [ECMAScript modules](https://nodejs.org/api/esm.html), you can use `next.config.mjs`:
next.config.mjs
// @ts-check
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
}
export default nextConfig
You can also use a function:
next.config.mjs
// @ts-check
export default (phase, { defaultConfig }) => {
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
}
return nextConfig
}
Since Next.js 12.1.0, you can use an async function:
next.config.js
// @ts-check
module.exports = async (phase, { defaultConfig }) => {
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
}
return nextConfig
}
`phase` is the current context in which the configuration is loaded. You can see the [available phases](https://github.com/vercel/next.js/blob/5e6b008b561caf2710ab7be63320a3d549474a5b/packages/next/shared/lib/constants.ts#L19-L23). Phases can be imported from `next/constants`:
// @ts-check
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
return {
/* development only config options here */
}
}
return {
/* config options for all phases except development here */
}
}
The commented lines are the place where you can put the configs allowed by `next.config.js`, which are [defined in this file](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/config-shared.ts).
However, none of the configs are required, and it's not necessary to understand what each config does. Instead, search for the features you need to enable or modify in this section and they will show you what to do.
> Avoid using new JavaScript features not available in your target Node.js version. `next.config.js` will not be parsed by Webpack, Babel or TypeScript.
This page documents all the available configuration options:
[
### assetPrefix
Learn how to use the assetPrefix config option to configure your CDN.
](/docs/pages/api-reference/next-config-js/assetPrefix)[
### basePath
Use \`basePath\` to deploy a Next.js application under a sub-path of a domain.
](/docs/pages/api-reference/next-config-js/basePath)[
### compress
Next.js provides gzip compression to compress rendered content and static files, it only works with the server target. Learn more about it here.
](/docs/pages/api-reference/next-config-js/compress)[
### crossOrigin
Use the \`crossOrigin\` option to add a crossOrigin tag on the \`script\` tags generated by \`next/script\` and \`next/head\`.
](/docs/pages/api-reference/next-config-js/crossOrigin)[
### devIndicators
Optimized pages include an indicator to let you know if it's being statically optimized. You can opt-out of it here.
](/docs/pages/api-reference/next-config-js/devIndicators)[
### distDir
Set a custom build directory to use instead of the default .next directory.
](/docs/pages/api-reference/next-config-js/distDir)[
### env
Learn to add and access environment variables in your Next.js application at build time.
](/docs/pages/api-reference/next-config-js/env)[
### eslint
Next.js reports ESLint errors and warnings during builds by default. Learn how to opt-out of this behavior here.
](/docs/pages/api-reference/next-config-js/eslint)[
### exportPathMap
Customize the pages that will be exported as HTML files when using \`next export\`.
](/docs/pages/api-reference/next-config-js/exportPathMap)[
### generateBuildId
Configure the build id, which is used to identify the current build in which your application is being served.
](/docs/pages/api-reference/next-config-js/generateBuildId)[
### generateEtags
Next.js will generate etags for every page by default. Learn more about how to disable etag generation here.
](/docs/pages/api-reference/next-config-js/generateEtags)[
### headers
Add custom HTTP headers to your Next.js app.
](/docs/pages/api-reference/next-config-js/headers)[
### httpAgentOptions
Next.js will automatically use HTTP Keep-Alive by default. Learn more about how to disable HTTP Keep-Alive here.
](/docs/pages/api-reference/next-config-js/httpAgentOptions)[
### images
Custom configuration for the next/image loader
](/docs/pages/api-reference/next-config-js/images)[
### instrumentationHook
Use the instrumentationHook option to set up instrumentation in your Next.js App.
](/docs/pages/api-reference/next-config-js/instrumentationHook)[
### onDemandEntries
Configure how Next.js will dispose and keep in memory pages created in development.
](/docs/pages/api-reference/next-config-js/onDemandEntries)[
### optimizePackageImports
API Reference for optmizedPackageImports Next.js Config Option
](/docs/pages/api-reference/next-config-js/optimizePackageImports)[
### output
Next.js automatically traces which files are needed by each page to allow for easy deployment of your application. Learn how it works here.
](/docs/pages/api-reference/next-config-js/output)[
### pageExtensions
Extend the default page extensions used by Next.js when resolving pages in the Pages Router.
](/docs/pages/api-reference/next-config-js/pageExtensions)[
### poweredByHeader
Next.js will add the \`x-powered-by\` header by default. Learn to opt-out of it here.
](/docs/pages/api-reference/next-config-js/poweredByHeader)[
### productionBrowserSourceMaps
Enables browser source map generation during the production build.
](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)[
### reactStrictMode
The complete Next.js runtime is now Strict Mode-compliant, learn how to opt-in
](/docs/pages/api-reference/next-config-js/reactStrictMode)[
### redirects
Add redirects to your Next.js app.
](/docs/pages/api-reference/next-config-js/redirects)[
### rewrites
Add rewrites to your Next.js app.
](/docs/pages/api-reference/next-config-js/rewrites)[
### Runtime Config
Add client and server runtime configuration to your Next.js app.
](/docs/pages/api-reference/next-config-js/runtime-configuration)[
### trailingSlash
Configure Next.js pages to resolve with or without a trailing slash.
](/docs/pages/api-reference/next-config-js/trailingSlash)[
### transpilePackages
Automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (\`node\_modules\`).
](/docs/pages/api-reference/next-config-js/transpilePackages)[
### turbo
Configure Next.js with Turbopack-specific options
](/docs/pages/api-reference/next-config-js/turbo)[
### typescript
Next.js reports TypeScript errors by default. Learn to opt-out of this behavior here.
](/docs/pages/api-reference/next-config-js/typescript)[
### urlImports
Configure Next.js to allow importing modules from external URLs (experimental).
](/docs/pages/api-reference/next-config-js/urlImports)[
### webpack
Learn how to customize the webpack config used by Next.js
](/docs/pages/api-reference/next-config-js/webpack)[
### webVitalsAttribution
Learn how to use the webVitalsAttribution option to pinpoint the source of Web Vitals issues.
](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
[Previous
userAgent
](/docs/pages/api-reference/functions/userAgent)
[Next
assetPrefix
](/docs/pages/api-reference/next-config-js/assetPrefix)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"068b4cfafa87e7883eb446fd59883eca\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/distDir | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [
distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/distDir.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)distDir
distDir
=======
You can specify a name to use for a custom build directory to use instead of `.next`.
Open `next.config.js` and add the `distDir` config:
next.config.js
module.exports = {
distDir: 'build',
}
Now if you run `next build` Next.js will use `build` instead of the default `.next` folder.
> `distDir` **should not** leave your project directory. For example, `../build` is an **invalid** directory.
[Previous
devIndicators
](/docs/pages/api-reference/next-config-js/devIndicators)
[Next
env
](/docs/pages/api-reference/next-config-js/env)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"c438cc572dfcfac55b6b02e81d997d6d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/webpack | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [
webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [nextRuntime](#nextruntime)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/webpack.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)webpack
Custom Webpack Config
=====================
> **Good to know**: changes to webpack config are not covered by semver so proceed at your own risk
Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case:
* [CSS imports](/docs/pages/building-your-application/styling)
* [CSS modules](/docs/pages/building-your-application/styling/css-modules)
* [Sass/SCSS imports](/docs/pages/building-your-application/styling/sass)
* [Sass/SCSS modules](/docs/pages/building-your-application/styling/sass)
* [Customizing babel configuration](/docs/pages/building-your-application/configuring/babel)
Some commonly asked for features are available as plugins:
* [@next/mdx](https://github.com/vercel/next.js/tree/canary/packages/next-mdx)
* [@next/bundle-analyzer](https://github.com/vercel/next.js/tree/canary/packages/next-bundle-analyzer)
In order to extend our usage of `webpack`, you can define a function that extends its config inside `next.config.js`, like so:
next.config.js
module.exports = {
webpack: (
config,
{ buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
) => {
// Important: return the modified config
return config
},
}
> The `webpack` function is executed three times, twice for the server (nodejs / edge runtime) and once for the client. This allows you to distinguish between client and server configuration using the `isServer` property.
The second argument to the `webpack` function is an object with the following properties:
* `buildId`: `String` - The build id, used as a unique identifier between builds
* `dev`: `Boolean` - Indicates if the compilation will be done in development
* `isServer`: `Boolean` - It's `true` for server-side compilation, and `false` for client-side compilation
* `nextRuntime`: `String | undefined` - The target runtime for server-side compilation; either `"edge"` or `"nodejs"`, it's `undefined` for client-side compilation.
* `defaultLoaders`: `Object` - Default loaders used internally by Next.js:
* `babel`: `Object` - Default `babel-loader` configuration
Example usage of `defaultLoaders.babel`:
// Example config for adding a loader that depends on babel-loader
// This source was taken from the @next/mdx plugin source:
// https://github.com/vercel/next.js/tree/canary/packages/next-mdx
module.exports = {
webpack: (config, options) => {
config.module.rules.push({
test: /\.mdx/,
use: [
options.defaultLoaders.babel,
{
loader: '@mdx-js/loader',
options: pluginOptions.options,
},
],
})
return config
},
}
#### [`nextRuntime`](#nextruntime)
Notice that `isServer` is `true` when `nextRuntime` is `"edge"` or `"nodejs"`, nextRuntime "`edge`" is currently for middleware and Server Components in edge runtime only.
[Previous
urlImports
](/docs/pages/api-reference/next-config-js/urlImports)
[Next
webVitalsAttribution
](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"41deb2452fecb8bff616734c34b5f953\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-cli | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Development](#development)
* [Turbopack](#turbopack)
* [HTTPS for Local Development](#https-for-local-development)
* [Build](#build)
* [Debug](#debug)
* [Linting](#linting)
* [Mangling](#mangling)
* [Profiling](#profiling)
* [Production](#production)
* [Keep Alive Timeout](#keep-alive-timeout)
* [Info](#info)
* [Lint](#lint)
* [Telemetry](#telemetry)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/05-next-cli.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)Next.js CLI
Next.js CLI
===========
The Next.js CLI allows you to develop, build, start your application, and more.
To get a list of the available CLI commands, run the following command inside your project directory:
Terminal
next -h
The output should look like this:
Terminal
Usage next [options] [command]
The Next.js CLI allows you to develop, build, start your application, and more.
Options:
-v, --version Outputs the Next.js version.
-h, --help Displays this message.
Commands:
build [directory] [options] Creates an optimized production build of your application.
The output displays information about each route.
dev [directory] [options] Starts Next.js in development mode with hot-code reloading,
error reporting, and more.
info [options] Prints relevant details about the current system which can be
used to report Next.js bugs.
lint [directory] [options] Runs ESLint for all files in the `/src`, `/app`, `/pages`,
`/components`, and `/lib` directories. It also provides a
guided setup to install any required dependencies if ESLint
is not already configured in your application.
start [directory] [options] Starts Next.js in production mode. The application should be
compiled with `next build` first.
telemetry [options] Allows you to enable or disable Next.js' completely
anonymous telemetry collection.
You can pass any [node arguments](https://nodejs.org/api/cli.html#cli_node_options_options) to `next` commands:
Terminal
NODE_OPTIONS='--throw-deprecation' next
NODE_OPTIONS='-r esm' next
NODE_OPTIONS='--inspect' next
> **Good to know**: Running `next` without a command is the same as running `next dev`
[Development](#development)
---------------------------
`next dev` starts the application in development mode with hot-code reloading, error reporting, and more.
To get a list of the available options with `next dev`, run the following command inside your project directory:
Terminal
next dev -h
The output should look like this:
Terminal
Usage: next dev [directory] [options]
Starts Next.js in development mode with hot-code reloading, error reporting, and more.
Arguments:
[directory] A directory on which to build the application.
If no directory is provided, the current
directory will be used.
Options:
--turbo Starts development mode using Turbopack (beta).
-p, --port <port> Specify a port number on which to start the
application. (default: 3000, env: PORT)
-H, --hostname <hostname> Specify a hostname on which to start the
application (default: 0.0.0.0).
--experimental-https Starts the server with HTTPS and generates a
self-signed certificate.
--experimental-https-key, <path> Path to a HTTPS key file.
--experimental-https-cert, <path> Path to a HTTPS certificate file.
--experimental-https-ca, <path> Path to a HTTPS certificate authority file.
--experimental-upload-trace, <traceUrl> Reports a subset of the debugging trace to a
remote HTTP URL. Includes sensitive data.
-h, --help Displays this message.
The application will start at `http://localhost:3000` by default. The default port can be changed with `-p`, like so:
Terminal
next dev -p 4000
Or using the `PORT` environment variable:
Terminal
PORT=4000 next dev
> **Good to know**:
>
> * `PORT` cannot be set in `.env` as booting up the HTTP server happens before any other code is initialized.
> * Next.js will automatically retry with another port until a port is available if a port is not specified with the CLI option `--port` or the `PORT` environment variable.
You can also set the hostname to be different from the default of `0.0.0.0`, this can be useful for making the application available for other devices on the network. The default hostname can be changed with `-H`, like so:
Terminal
next dev -H 192.168.1.2
### [Turbopack](#turbopack)
[Turbopack](/docs/architecture/turbopack) (beta), our new bundler, which is being tested and stabilized in Next.js, helps speed up local iterations while working on your application.
To use Turbopack in development mode, add the `--turbo` option:
Terminal
next dev --turbo
### [HTTPS for Local Development](#https-for-local-development)
For certain use cases like webhooks or authentication, it may be required to use HTTPS to have a secure environment on `localhost`. Next.js can generate a self-signed certificate with `next dev` as follows:
Terminal
next dev --experimental-https
You can also provide a custom certificate and key with `--experimental-https-key` and `--experimental-https-cert`. Optionally, you can provide a custom CA certificate with `--experimental-https-ca` as well.
Terminal
next dev --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem
`next dev --experimental-https` is only intended for development and creates a locally-trusted certificate with `mkcert`. In production, use properly issued certificates from trusted authorities. When deploying to Vercel, HTTPS is [automatically configured](https://vercel.com/docs/security/encryption) for your Next.js application.
[Build](#build)
---------------
`next build` creates an optimized production build of your application. The output displays information about each route:
Terminal
Route (app) Size First Load JS
┌ ○ / 5.3 kB 89.5 kB
├ ○ /_not-found 885 B 85.1 kB
└ ○ /about 137 B 84.4 kB
+ First Load JS shared by all 84.2 kB
├ chunks/184-d3bb186aac44da98.js 28.9 kB
├ chunks/30b509c0-f3503c24f98f3936.js 53.4 kB
└ other shared chunks (total)
○ (Static) prerendered as static content
* **Size**: The number of assets downloaded when navigating to the page client-side. The size for each route only includes its dependencies.
* **First Load JS**: The number of assets downloaded when visiting the page from the server. The amount of JS shared by all is shown as a separate metric.
Both of these values are [**compressed with gzip**](/docs/app/api-reference/next-config-js/compress). The first load is indicated by green, yellow, or red. Aim for green for performant applications.
To get a list of the available options with `next build`, run the following command inside your project directory:
Terminal
next build -h
The output should look like this:
Terminal
Usage: next build [directory] [options]
Creates an optimized production build of your application. The output displays information
about each route.
Arguments:
[directory] A directory on which to build the application. If no
provided, the current directory will be
used.
Options:
-d, --debug Enables a more verbose build output.
--profile Enables production profiling for React.
--no-lint Disables linting.
--no-mangling Disables mangling.
--experimental-app-only Builds only App Router routes.
--experimental-build-mode [mode] Uses an experimental build mode. (choices: "compile"
"generate", default: "default")
-h, --help Displays this message.
### [Debug](#debug)
You can enable more verbose build output with the `--debug` flag in `next build`.
Terminal
next build --debug
With this flag enabled additional build output like rewrites, redirects, and headers will be shown.
### [Linting](#linting)
You can disable linting for builds like so:
Terminal
next build --no-lint
### [Mangling](#mangling)
You can disable [mangling](https://en.wikipedia.org/wiki/Name_mangling) for builds like so:
Terminal
next build --no-mangling
> **Good to know**: This may affect performance and should only be used for debugging purposes.
### [Profiling](#profiling)
You can enable production profiling for React with the `--profile` flag in `next build`.
Terminal
next build --profile
After that, you can use the profiler in the same way as you would in development.
[Production](#production)
-------------------------
`next start` starts the application in production mode. The application should be compiled with [`next build`](#build) first.
To get a list of the available options with `next start`, run the follow command inside your project directory:
Terminal
next start -h
The output should look like this:
Terminal
Usage: next start [directory] [options]
Starts Next.js in production mode. The application should be compiled with `next build`
first.
Arguments:
[directory] A directory on which to start the application.
If not directory is provided, the current
directory will be used.
Options:
-p, --port <port> Specify a port number on which to start the
application. (default: 3000, env: PORT)
-H, --hostname <hostname> Specify a hostname on which to start the
application (default: 0.0.0.0).
--keepAliveTimeout <keepAliveTimeout> Specify the maximum amount of milliseconds to wait
before closing the inactive connections.
-h, --help Displays this message.
The application will start at `http://localhost:3000` by default. The default port can be changed with `-p`, like so:
Terminal
next start -p 4000
Or using the `PORT` environment variable:
Terminal
PORT=4000 next start
> **Good to know**:
>
> * `PORT` cannot be set in `.env` as booting up the HTTP server happens before any other code is initialized.
> * `next start` cannot be used with `output: 'standalone'` or `output: 'export'`.
### [Keep Alive Timeout](#keep-alive-timeout)
When deploying Next.js behind a downstream proxy (e.g. a load-balancer like AWS ELB/ALB) it's important to configure Next's underlying HTTP server with [keep-alive timeouts](https://nodejs.org/api/http.html#http_server_keepalivetimeout) that are _larger_ than the downstream proxy's timeouts. Otherwise, once a keep-alive timeout is reached for a given TCP connection, Node.js will immediately terminate that connection without notifying the downstream proxy. This results in a proxy error whenever it attempts to reuse a connection that Node.js has already terminated.
To configure the timeout values for the production Next.js server, pass `--keepAliveTimeout` (in milliseconds) to `next start`, like so:
Terminal
next start --keepAliveTimeout 70000
[Info](#info)
-------------
`next info` prints relevant details about the current system which can be used to report Next.js bugs. This information includes Operating System platform/arch/version, Binaries (Node.js, npm, Yarn, pnpm) and npm package versions (`next`, `react`, `react-dom`).
To get a list of the available options with `next info`, run the following command inside your project directory:
Terminal
next info -h
The output should look like this:
Terminal
Usage: next info [options]
Prints relevant details about the current system which can be used to report Next.js bugs.
Options:
--verbose Collections additional information for debugging.
-h, --help Displays this message.
Running `next info` will give you information like this example:
Terminal
Operating System:
Platform: linux
Arch: x64
Version: #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021
Available memory (MB): 31795
Available CPU cores: 16
Binaries:
Node: 16.13.0
npm: 8.1.0
Yarn: 1.22.17
pnpm: 6.24.2
Relevant Packages:
next: 14.1.1-canary.61 // Latest available version is detected (14.1.1-canary.61).
react: 18.2.0
react-dom: 18.2.0
Next.js Config:
output: N/A
This information should then be pasted into GitHub Issues.
You can also run `next info --verbose` which will print additional information about the system and the installation of packages related to `next`.
[Lint](#lint)
-------------
`next lint` runs ESLint for all files in the `pages/`, `app/`, `components/`, `lib/`, and `src/` directories. It also provides a guided setup to install any required dependencies if ESLint is not already configured in your application.
To get a list of the available options with `next lint`, run the following command inside your project directory:
Terminal
next lint -h
The output should look like this:
Terminal
Usage: next lint [directory] [options]
Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` directories. It also
provides a guided setup to install any required dependencies if ESLint is not already configured in your
application.
Arguments:
[directory] A base directory on which to lint the application.
If no directory is provided, the current directory
will be used.
Options:
-d, --dir, <dirs...> Include directory, or directories, to run ESLint.
--file, <files...> Include file, or files, to run ESLint.
--ext, [exts...] Specify JavaScript file extensions. (default:
[".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"])
-c, --config, <config> Uses this configuration file, overriding all other
configuration options.
--resolve-plugins-relative-to, <rprt> Specify a directory where plugins should be resolved
from.
--strict Creates a `.eslintrc.json` file using the Next.js
strict configuration.
--rulesdir, <rulesdir...> Uses additional rules from this directory(s).
--fix Automatically fix linting issues.
--fix-type <fixType> Specify the types of fixes to apply (e.g., problem,
suggestion, layout).
--ignore-path <path> Specify a file to ignore.
--no-ignore <path> Disables the `--ignore-path` option.
--quiet Reports errors only.
--max-warnings [maxWarnings] Specify the number of warnings before triggering a
non-zero exit code. (default: -1)
-o, --output-file, <outputFile> Specify a file to write report to.
-f, --format, <format> Uses a specifc output format.
--no-inline-config Prevents comments from changing config or rules.
--report-unused-disable-directives-severity <level> Specify severity level for unused eslint-disable
directives. (choices: "error", "off", "warn")
--no-cache Disables caching.
--cache-location, <cacheLocation> Specify a location for cache.
--cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed files
in the cache. (default: "metadata")
--error-on-unmatched-pattern Reports errors when any file patterns are unmatched.
-h, --help Displays this message.
If you have other directories that you would like to lint, you can specify them using the `--dir` flag:
Terminal
next lint --dir utils
For more information on the other options, check out our [ESLint](/docs/app/building-your-application/configuring/eslint) configuration documentation.
[Telemetry](#telemetry)
-----------------------
Next.js collects **completely anonymous** telemetry data about general usage. Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information.
To get a list of the available options with `next telemetry`, run the following command in your project directory:
Terminal
next telemetry -h
The output should look like this:
Terminal
Usage: next telemetry [options]
Allows you to enable or disable Next.js' completely anonymous telemetry collection.
Options:
--enable Eanbles Next.js' telemetry collection.
--disable Disables Next.js' telemetry collection.
-h, --help Displays this message.
Learn more: https://nextjs.org/telemetry
Learn more about [Telemetry](/telemetry).
[Previous
create-next-app
](/docs/pages/api-reference/create-next-app)
[Next
Edge Runtime
](/docs/pages/api-reference/edge)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"d1fa4bd186f548f038fee84a59f12d0a\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/webVitalsAttribution | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [
webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/webVitalsAttribution.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)webVitalsAttribution
webVitalsAttribution
====================
When debugging issues related to Web Vitals, it is often helpful if we can pinpoint the source of the problem. For example, in the case of Cumulative Layout Shift (CLS), we might want to know the first element that shifted when the single largest layout shift occurred. Or, in the case of Largest Contentful Paint (LCP), we might want to identify the element corresponding to the LCP for the page. If the LCP element is an image, knowing the URL of the image resource can help us locate the asset we need to optimize.
Pinpointing the biggest contributor to the Web Vitals score, aka [attribution](https://github.com/GoogleChrome/web-vitals/blob/4ca38ae64b8d1e899028c692f94d4c56acfc996c/README.md#attribution), allows us to obtain more in-depth information like entries for [PerformanceEventTiming](https://developer.mozilla.org/docs/Web/API/PerformanceEventTiming), [PerformanceNavigationTiming](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming) and [PerformanceResourceTiming](https://developer.mozilla.org/docs/Web/API/PerformanceResourceTiming).
Attribution is disabled by default in Next.js but can be enabled **per metric** by specifying the following in `next.config.js`.
next.config.js
experimental: {
webVitalsAttribution: ['CLS', 'LCP']
}
Valid attribution values are all `web-vitals` metrics specified in the [`NextWebVitalsMetric`](https://github.com/vercel/next.js/blob/442378d21dd56d6e769863eb8c2cb521a463a2e0/packages/next/shared/lib/utils.ts#L43) type.
[Previous
webpack
](/docs/pages/api-reference/next-config-js/webpack)
[Next
create-next-app
](/docs/pages/api-reference/create-next-app)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f430021499f9977cd1b9885c12739059\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/create-next-app | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Interactive](#interactive)
* [Non-interactive](#non-interactive)
* [Why use Create Next App?](#why-use-create-next-app)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/04-create-next-app.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)create-next-app
create-next-app
===============
The easiest way to get started with Next.js is by using `create-next-app`. This CLI tool enables you to quickly start building a new Next.js application, with everything set up for you.
You can create a new app using the default Next.js template, or by using one of the [official Next.js examples](https://github.com/vercel/next.js/tree/canary/examples).
### [Interactive](#interactive)
You can create a new project interactively by running:
Terminal
npx create-next-app@latest
Terminal
yarn create next-app
Terminal
pnpm create next-app
Terminal
bunx create-next-app
You will then be asked the following prompts:
Terminal
What is your project named? my-app
Would you like to use TypeScript? No / Yes
Would you like to use ESLint? No / Yes
Would you like to use Tailwind CSS? No / Yes
Would you like to use `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to customize the default import alias (@/*)? No / Yes
Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers.
### [Non-interactive](#non-interactive)
You can also pass command line arguments to set up a new project non-interactively.
Further, you can negate default options by prefixing them with `--no-` (e.g. `--no-eslint`).
See `create-next-app --help`:
Terminal
Usage: create-next-app <project-directory> [options]
Options:
-V, --version output the version number
--ts, --typescript
Initialize as a TypeScript project. (default)
--js, --javascript
Initialize as a JavaScript project.
--tailwind
Initialize with Tailwind CSS config. (default)
--eslint
Initialize with ESLint config.
--app
Initialize as an App Router project.
--src-dir
Initialize inside a `src/` directory.
--import-alias <alias-to-configure>
Specify import alias to use (default "@/*").
--use-npm
Explicitly tell the CLI to bootstrap the app using npm
--use-pnpm
Explicitly tell the CLI to bootstrap the app using pnpm
--use-yarn
Explicitly tell the CLI to bootstrap the app using Yarn
--use-bun
Explicitly tell the CLI to bootstrap the app using Bun
-e, --example [name]|[github-url]
An example to bootstrap the app with. You can use an example name
from the official Next.js repo or a public GitHub URL. The URL can use
any branch and/or subdirectory
--example-path <path-to-example>
In a rare case, your GitHub URL might contain a branch name with
a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar).
In this case, you must specify the path to the example separately:
--example-path foo/bar
--reset-preferences
Explicitly tell the CLI to reset any stored preferences
-h, --help output usage information
### [Why use Create Next App?](#why-use-create-next-app)
`create-next-app` allows you to create a new Next.js app within seconds. It is officially maintained by the creators of Next.js, and includes a number of benefits:
* **Interactive Experience**: Running `npx create-next-app@latest` (with no arguments) launches an interactive experience that guides you through setting up a project.
* **Zero Dependencies**: Initializing a project is as quick as one second. Create Next App has zero dependencies.
* **Offline Support**: Create Next App will automatically detect if you're offline and bootstrap your project using your local package cache.
* **Support for Examples**: Create Next App can bootstrap your application using an example from the Next.js examples collection (e.g. `npx create-next-app --example api-routes`) or any public GitHub repository.
* **Tested**: The package is part of the Next.js monorepo and tested using the same integration test suite as Next.js itself, ensuring it works as expected with every release.
[Previous
webVitalsAttribution
](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
[Next
Next.js CLI
](/docs/pages/api-reference/next-cli)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"6675d061040a244e8e55a94ee9bbf023\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/compress | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [
compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Disabling compression](#disabling-compression)
* [Changing the compression algorithm](#changing-the-compression-algorithm)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/compress.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)compress
compress
========
By default, Next.js uses `gzip` to compress rendered content and static files when using `next start` or a custom server. This is an optimization for applications that do not have compression configured. If compression is _already_ configured in your application via a custom server, Next.js will not add compression.
> **Good to know:**
>
> * When hosting your application on [Vercel](https://vercel.com/docs/edge-network/compression), compression uses `brotli` first, then `gzip`.
> * You can check if compression is enabled and which algorithm is used by looking at the [`Accept-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) (browser accepted options) and [`Content-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding) (currently used) headers in the response.
[Disabling compression](#disabling-compression)
-----------------------------------------------
To disable **compression**, set the `compress` config option to `false`:
next.config.js
module.exports = {
compress: false,
}
We do not recommend disabling compression unless you have compression configured on your server, as compression reduces bandwidth usage and improves the performance of your application.
[Changing the compression algorithm](#changing-the-compression-algorithm)
-------------------------------------------------------------------------
To change your compression algorithm, you will need to configure your custom server and set the `compress` option to `false` in your `next.config.js` file.
For example, you're using [nginx](https://www.nginx.com/) and want to switch to `brotli`, set the `compress` option to `false` to allow nginx to handle compression.
> **Good to know:**
>
> * For Next.js applications on Vercel, compression is handled by the Vercel's Edge Network and not Next.js. See the [Vercel documentation](https://vercel.com/docs/edge-network/compression) for more information.
[Previous
basePath
](/docs/pages/api-reference/next-config-js/basePath)
[Next
crossOrigin
](/docs/pages/api-reference/next-config-js/crossOrigin)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"30663c6694a9e96d3721aa5705644938\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/exportPathMap | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [
exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Adding a trailing slash](#adding-a-trailing-slash)
* [Customizing the output directory](#customizing-the-output-directory)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/exportPathMap.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)exportPathMap
exportPathMap
=============
> This feature is exclusive to `next export` and currently **deprecated** in favor of `getStaticPaths` with `pages` or `generateStaticParams` with `app`.
Examples
* [Static Export](https://github.com/vercel/next.js/tree/canary/examples/with-static-export)
`exportPathMap` allows you to specify a mapping of request paths to page destinations, to be used during export. Paths defined in `exportPathMap` will also be available when using [`next dev`](/docs/app/api-reference/next-cli#development).
Let's start with an example, to create a custom `exportPathMap` for an app with the following pages:
* `pages/index.js`
* `pages/about.js`
* `pages/post.js`
Open `next.config.js` and add the following `exportPathMap` config:
next.config.js
module.exports = {
exportPathMap: async function (
defaultPathMap,
{ dev, dir, outDir, distDir, buildId }
) {
return {
'/': { page: '/' },
'/about': { page: '/about' },
'/p/hello-nextjs': { page: '/post', query: { title: 'hello-nextjs' } },
'/p/learn-nextjs': { page: '/post', query: { title: 'learn-nextjs' } },
'/p/deploy-nextjs': { page: '/post', query: { title: 'deploy-nextjs' } },
}
},
}
> **Good to know**: the `query` field in `exportPathMap` cannot be used with [automatically statically optimized pages](/docs/pages/building-your-application/rendering/automatic-static-optimization) or [`getStaticProps` pages](/docs/pages/building-your-application/data-fetching/get-static-props) as they are rendered to HTML files at build-time and additional query information cannot be provided during `next export`.
The pages will then be exported as HTML files, for example, `/about` will become `/about.html`.
`exportPathMap` is an `async` function that receives 2 arguments: the first one is `defaultPathMap`, which is the default map used by Next.js. The second argument is an object with:
* `dev` - `true` when `exportPathMap` is being called in development. `false` when running `next export`. In development `exportPathMap` is used to define routes.
* `dir` - Absolute path to the project directory
* `outDir` - Absolute path to the `out/` directory ([configurable with `-o`](#customizing-the-output-directory)). When `dev` is `true` the value of `outDir` will be `null`.
* `distDir` - Absolute path to the `.next/` directory (configurable with the [`distDir`](/docs/pages/api-reference/next-config-js/distDir) config)
* `buildId` - The generated build id
The returned object is a map of pages where the `key` is the `pathname` and the `value` is an object that accepts the following fields:
* `page`: `String` - the page inside the `pages` directory to render
* `query`: `Object` - the `query` object passed to `getInitialProps` when prerendering. Defaults to `{}`
> The exported `pathname` can also be a filename (for example, `/readme.md`), but you may need to set the `Content-Type` header to `text/html` when serving its content if it is different than `.html`.
[Adding a trailing slash](#adding-a-trailing-slash)
---------------------------------------------------
It is possible to configure Next.js to export pages as `index.html` files and require trailing slashes, `/about` becomes `/about/index.html` and is routable via `/about/`. This was the default behavior prior to Next.js 9.
To switch back and add a trailing slash, open `next.config.js` and enable the `trailingSlash` config:
next.config.js
module.exports = {
trailingSlash: true,
}
[Customizing the output directory](#customizing-the-output-directory)
---------------------------------------------------------------------
[`next export`](/docs/pages/building-your-application/deploying/static-exports) will use `out` as the default output directory, you can customize this using the `-o` argument, like so:
Terminal
next export -o outdir
> **Warning**: Using `exportPathMap` is deprecated and is overridden by `getStaticPaths` inside `pages`. We don't recommend using them together.
[Previous
eslint
](/docs/pages/api-reference/next-config-js/eslint)
[Next
generateBuildId
](/docs/pages/api-reference/next-config-js/generateBuildId)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"3881d31a3db03be52f0fcb341a845b6c\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
Architecture
============
Learn about the Next.js architecture and how it works under the hood.
[
### Accessibility
The built-in accessibility features of Next.js.
](/docs/architecture/accessibility)[
### Fast Refresh
Fast Refresh is a hot module reloading experience that gives you instantaneous feedback on edits made to your React components.
](/docs/architecture/fast-refresh)[
### Next.js Compiler
Next.js Compiler, written in Rust, which transforms and minifies your Next.js application.
](/docs/architecture/nextjs-compiler)[
### Supported Browsers
Browser support and which JavaScript features are supported by Next.js.
](/docs/architecture/supported-browsers)[
### Turbopack
Turbopack is an incremental bundler optimized for JavaScript and TypeScript, written in Rust, and built into Next.js.
](/docs/architecture/turbopack)
[Previous
Next.js CLI
](/docs/app/api-reference/next-cli)
[Next
Accessibility
](/docs/architecture/accessibility)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"23efcd0fcaecd8233e4cb09b511563e0\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/basePath | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [
basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Links](#links)
* [Images](#images)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/basePath.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)basePath
basePath
========
To deploy a Next.js application under a sub-path of a domain you can use the `basePath` config option.
`basePath` allows you to set a path prefix for the application. For example, to use `/docs` instead of `''` (an empty string, the default), open `next.config.js` and add the `basePath` config:
next.config.js
module.exports = {
basePath: '/docs',
}
> **Good to know**: This value must be set at build time and cannot be changed without re-building as the value is inlined in the client-side bundles.
### [Links](#links)
When linking to other pages using `next/link` and `next/router` the `basePath` will be automatically applied.
For example, using `/about` will automatically become `/docs/about` when `basePath` is set to `/docs`.
export default function HomePage() {
return (
<>
<Link href="/about">About Page</Link>
</>
)
}
Output html:
<a href="/docs/about">About Page</a>
This makes sure that you don't have to change all links in your application when changing the `basePath` value.
### [Images](#images)
When using the [`next/image`](/docs/pages/api-reference/components/image) component, you will need to add the `basePath` in front of `src`.
For example, using `/docs/me.png` will properly serve your image when `basePath` is set to `/docs`.
import Image from 'next/image'
function Home() {
return (
<>
<h1>My Homepage</h1>
<Image
src="/docs/me.png"
alt="Picture of the author"
width={500}
height={500}
/>
<p>Welcome to my homepage!</p>
</>
)
}
export default Home
[Previous
assetPrefix
](/docs/pages/api-reference/next-config-js/assetPrefix)
[Next
compress
](/docs/pages/api-reference/next-config-js/compress)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"f8dae3dd3704d6a286cc70c9a27bcaef\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/eslint | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [
eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/eslint.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)eslint
eslint
======
When ESLint is detected in your project, Next.js fails your **production build** (`next build`) when errors are present.
If you'd like Next.js to produce production code even when your application has ESLint errors, you can disable the built-in linting step completely. This is not recommended unless you already have ESLint configured to run in a separate part of your workflow (for example, in CI or a pre-commit hook).
Open `next.config.js` and enable the `ignoreDuringBuilds` option in the `eslint` config:
next.config.js
module.exports = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
}
[Previous
env
](/docs/pages/api-reference/next-config-js/env)
[Next
exportPathMap
](/docs/pages/api-reference/next-config-js/exportPathMap)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"6808971cf7449f6182e9568d92c07f82\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/edge | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Network APIs](#network-apis)
* [Encoding APIs](#encoding-apis)
* [Stream APIs](#stream-apis)
* [Crypto APIs](#crypto-apis)
* [Web Standard APIs](#web-standard-apis)
* [Next.js Specific Polyfills](#nextjs-specific-polyfills)
* [Environment Variables](#environment-variables)
* [Unsupported APIs](#unsupported-apis)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/06-edge.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[API Reference](/docs/pages/api-reference)Edge Runtime
Edge Runtime
============
The Next.js Edge Runtime is based on standard Web APIs, it supports the following APIs:
[Network APIs](#network-apis)
-----------------------------
API
Description
[`Blob`](https://developer.mozilla.org/docs/Web/API/Blob)
Represents a blob
[`fetch`](https://developer.mozilla.org/docs/Web/API/Fetch_API)
Fetches a resource
[`FetchEvent`](https://developer.mozilla.org/docs/Web/API/FetchEvent)
Represents a fetch event
[`File`](https://developer.mozilla.org/docs/Web/API/File)
Represents a file
[`FormData`](https://developer.mozilla.org/docs/Web/API/FormData)
Represents form data
[`Headers`](https://developer.mozilla.org/docs/Web/API/Headers)
Represents HTTP headers
[`Request`](https://developer.mozilla.org/docs/Web/API/Request)
Represents an HTTP request
[`Response`](https://developer.mozilla.org/docs/Web/API/Response)
Represents an HTTP response
[`URLSearchParams`](https://developer.mozilla.org/docs/Web/API/URLSearchParams)
Represents URL search parameters
[`WebSocket`](https://developer.mozilla.org/docs/Web/API/WebSocket)
Represents a websocket connection
[Encoding APIs](#encoding-apis)
-------------------------------
API
Description
[`atob`](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/atob)
Decodes a base-64 encoded string
[`btoa`](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/btoa)
Encodes a string in base-64
[`TextDecoder`](https://developer.mozilla.org/docs/Web/API/TextDecoder)
Decodes a Uint8Array into a string
[`TextDecoderStream`](https://developer.mozilla.org/docs/Web/API/TextDecoderStream)
Chainable decoder for streams
[`TextEncoder`](https://developer.mozilla.org/docs/Web/API/TextEncoder)
Encodes a string into a Uint8Array
[`TextEncoderStream`](https://developer.mozilla.org/docs/Web/API/TextEncoderStream)
Chainable encoder for streams
[Stream APIs](#stream-apis)
---------------------------
API
Description
[`ReadableStream`](https://developer.mozilla.org/docs/Web/API/ReadableStream)
Represents a readable stream
[`ReadableStreamBYOBReader`](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader)
Represents a reader of a ReadableStream
[`ReadableStreamDefaultReader`](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader)
Represents a reader of a ReadableStream
[`TransformStream`](https://developer.mozilla.org/docs/Web/API/TransformStream)
Represents a transform stream
[`WritableStream`](https://developer.mozilla.org/docs/Web/API/WritableStream)
Represents a writable stream
[`WritableStreamDefaultWriter`](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter)
Represents a writer of a WritableStream
[Crypto APIs](#crypto-apis)
---------------------------
API
Description
[`crypto`](https://developer.mozilla.org/docs/Web/API/Window/crypto)
Provides access to the cryptographic functionality of the platform
[`CryptoKey`](https://developer.mozilla.org/docs/Web/API/CryptoKey)
Represents a cryptographic key
[`SubtleCrypto`](https://developer.mozilla.org/docs/Web/API/SubtleCrypto)
Provides access to common cryptographic primitives, like hashing, signing, encryption or decryption
[Web Standard APIs](#web-standard-apis)
---------------------------------------
API
Description
[`AbortController`](https://developer.mozilla.org/docs/Web/API/AbortController)
Allows you to abort one or more DOM requests as and when desired
[`Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
Represents an array of values
[`ArrayBuffer`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
Represents a generic, fixed-length raw binary data buffer
[`Atomics`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
Provides atomic operations as static methods
[`BigInt`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
Represents a whole number with arbitrary precision
[`BigInt64Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
Represents a typed array of 64-bit signed integers
[`BigUint64Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array)
Represents a typed array of 64-bit unsigned integers
[`Boolean`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
Represents a logical entity and can have two values: `true` and `false`
[`clearInterval`](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval)
Cancels a timed, repeating action which was previously established by a call to `setInterval()`
[`clearTimeout`](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout)
Cancels a timed, repeating action which was previously established by a call to `setTimeout()`
[`console`](https://developer.mozilla.org/docs/Web/API/Console)
Provides access to the browser's debugging console
[`DataView`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/DataView)
Represents a generic view of an `ArrayBuffer`
[`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)
Represents a single moment in time in a platform-independent format
[`decodeURI`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
Decodes a Uniform Resource Identifier (URI) previously created by `encodeURI` or by a similar routine
[`decodeURIComponent`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
Decodes a Uniform Resource Identifier (URI) component previously created by `encodeURIComponent` or by a similar routine
[`DOMException`](https://developer.mozilla.org/docs/Web/API/DOMException)
Represents an error that occurs in the DOM
[`encodeURI`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character
[`encodeURIComponent`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character
[`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
Represents an error when trying to execute a statement or accessing a property
[`EvalError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
Represents an error that occurs regarding the global function `eval()`
[`Float32Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
Represents a typed array of 32-bit floating point numbers
[`Float64Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
Represents a typed array of 64-bit floating point numbers
[`Function`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function)
Represents a function
[`Infinity`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Infinity)
Represents the mathematical Infinity value
[`Int8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int8Array)
Represents a typed array of 8-bit signed integers
[`Int16Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int16Array)
Represents a typed array of 16-bit signed integers
[`Int32Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int32Array)
Represents a typed array of 32-bit signed integers
[`Intl`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl)
Provides access to internationalization and localization functionality
[`isFinite`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
Determines whether a value is a finite number
[`isNaN`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/isNaN)
Determines whether a value is `NaN` or not
[`JSON`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON)
Provides functionality to convert JavaScript values to and from the JSON format
[`Map`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)
Represents a collection of values, where each value may occur only once
[`Math`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Math)
Provides access to mathematical functions and constants
[`Number`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
Represents a numeric value
[`Object`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
Represents the object that is the base of all JavaScript objects
[`parseFloat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
Parses a string argument and returns a floating point number
[`parseInt`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
Parses a string argument and returns an integer of the specified radix
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
Represents the eventual completion (or failure) of an asynchronous operation, and its resulting value
[`Proxy`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
Represents an object that is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc)
[`queueMicrotask`](https://developer.mozilla.org/docs/Web/API/queueMicrotask)
Queues a microtask to be executed
[`RangeError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
Represents an error when a value is not in the set or range of allowed values
[`ReferenceError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
Represents an error when a non-existent variable is referenced
[`Reflect`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Reflect)
Provides methods for interceptable JavaScript operations
[`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
Represents a regular expression, allowing you to match combinations of characters
[`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)
Represents a collection of values, where each value may occur only once
[`setInterval`](https://developer.mozilla.org/docs/Web/API/setInterval)
Repeatedly calls a function, with a fixed time delay between each call
[`setTimeout`](https://developer.mozilla.org/docs/Web/API/setTimeout)
Calls a function or evaluates an expression after a specified number of milliseconds
[`SharedArrayBuffer`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
Represents a generic, fixed-length raw binary data buffer
[`String`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
Represents a sequence of characters
[`structuredClone`](https://developer.mozilla.org/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
Creates a deep copy of a value
[`Symbol`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
Represents a unique and immutable data type that is used as the key of an object property
[`SyntaxError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
Represents an error when trying to interpret syntactically invalid code
[`TypeError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
Represents an error when a value is not of the expected type
[`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
Represents a typed array of 8-bit unsigned integers
[`Uint8ClampedArray`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray)
Represents a typed array of 8-bit unsigned integers clamped to 0-255
[`Uint32Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array)
Represents a typed array of 32-bit unsigned integers
[`URIError`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/URIError)
Represents an error when a global URI handling function was used in a wrong way
[`URL`](https://developer.mozilla.org/docs/Web/API/URL)
Represents an object providing static methods used for creating object URLs
[`URLPattern`](https://developer.mozilla.org/docs/Web/API/URLPattern)
Represents a URL pattern
[`URLSearchParams`](https://developer.mozilla.org/docs/Web/API/URLSearchParams)
Represents a collection of key/value pairs
[`WeakMap`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
Represents a collection of key/value pairs in which the keys are weakly referenced
[`WeakSet`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
Represents a collection of objects in which each object may occur only once
[`WebAssembly`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly)
Provides access to WebAssembly
[Next.js Specific Polyfills](#nextjs-specific-polyfills)
--------------------------------------------------------
* [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage)
[Environment Variables](#environment-variables)
-----------------------------------------------
You can use `process.env` to access [Environment Variables](/docs/app/building-your-application/configuring/environment-variables) for both `next dev` and `next build`.
[Unsupported APIs](#unsupported-apis)
-------------------------------------
The Edge Runtime has some restrictions including:
* Native Node.js APIs **are not supported**. For example, you can't read or write to the filesystem.
* `node_modules` _can_ be used, as long as they implement ES Modules and do not use native Node.js APIs.
* Calling `require` directly is **not allowed**. Use ES Modules instead.
The following JavaScript language features are disabled, and **will not work:**
API
Description
[`eval`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/eval)
Evaluates JavaScript code represented as a string
[`new Function(evalString)`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function)
Creates a new function with the code provided as an argument
[`WebAssembly.compile`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
Compiles a WebAssembly module from a buffer source
[`WebAssembly.instantiate`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
Compiles and instantiates a WebAssembly module from a buffer source
In rare cases, your code could contain (or import) some dynamic code evaluation statements which _can not be reached at runtime_ and which can not be removed by treeshaking. You can relax the check to allow specific files with your Middleware or Edge API Route exported configuration:
export const config = {
runtime: 'edge', // for Edge API Routes only
unstable_allowDynamic: [
// allows a single file
'/lib/utilities.js',
// use a glob to allow anything in the function-bind 3rd party module
'/node_modules/function-bind/**',
],
}
`unstable_allowDynamic` is a [glob](https://github.com/micromatch/micromatch#matching-features), or an array of globs, ignoring dynamic code evaluation for specific files. The globs are relative to your application root folder.
Be warned that if these statements are executed on the Edge, _they will throw and cause a runtime error_.
[Previous
Next.js CLI
](/docs/pages/api-reference/next-cli)
[Next
Architecture
](/docs/architecture)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"cd2d2289fcefee25f18ea0818f13766d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/generateEtags | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [
generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/generateEtags.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)generateEtags
generateEtags
=============
Next.js will generate [etags](https://en.wikipedia.org/wiki/HTTP_ETag) for every page by default. You may want to disable etag generation for HTML pages depending on your cache strategy.
Open `next.config.js` and disable the `generateEtags` option:
next.config.js
module.exports = {
generateEtags: false,
}
[Previous
generateBuildId
](/docs/pages/api-reference/next-config-js/generateBuildId)
[Next
headers
](/docs/pages/api-reference/next-config-js/headers)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"ceb04bbc6361ab221bad18814788a323\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture/accessibility | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Route Announcements](#route-announcements)
* [Linting](#linting)
* [Accessibility Resources](#accessibility-resources)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/accessibility.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Architecture](/docs/architecture)Accessibility
Accessibility
=============
The Next.js team is committed to making Next.js accessible to all developers (and their end-users). By adding accessibility features to Next.js by default, we aim to make the Web more inclusive for everyone.
[Route Announcements](#route-announcements)
-------------------------------------------
When transitioning between pages rendered on the server (e.g. using the `<a href>` tag) screen readers and other assistive technology announce the page title when the page loads so that users understand that the page has changed.
In addition to traditional page navigations, Next.js also supports client-side transitions for improved performance (using `next/link`). To ensure that client-side transitions are also announced to assistive technology, Next.js includes a route announcer by default.
The Next.js route announcer looks for the page name to announce by first inspecting `document.title`, then the `<h1>` element, and finally the URL pathname. For the most accessible user experience, ensure that each page in your application has a unique and descriptive title.
[Linting](#linting)
-------------------
Next.js provides an [integrated ESLint experience](/docs/pages/building-your-application/configuring/eslint) out of the box, including custom rules for Next.js. By default, Next.js includes `eslint-plugin-jsx-a11y` to help catch accessibility issues early, including warning on:
* [aria-props](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/aria-props.md?rgh-link-date=2021-06-04T02%3A10%3A36Z)
* [aria-proptypes](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/aria-proptypes.md?rgh-link-date=2021-06-04T02%3A10%3A36Z)
* [aria-unsupported-elements](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/aria-unsupported-elements.md?rgh-link-date=2021-06-04T02%3A10%3A36Z)
* [role-has-required-aria-props](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/role-has-required-aria-props.md?rgh-link-date=2021-06-04T02%3A10%3A36Z)
* [role-supports-aria-props](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/role-supports-aria-props.md?rgh-link-date=2021-06-04T02%3A10%3A36Z)
For example, this plugin helps ensure you add alt text to `img` tags, use correct `aria-*` attributes, use correct `role` attributes, and more.
[Accessibility Resources](#accessibility-resources)
---------------------------------------------------
* [WebAIM WCAG checklist](https://webaim.org/standards/wcag/checklist)
* [WCAG 2.2 Guidelines](https://www.w3.org/TR/WCAG22/)
* [The A11y Project](https://www.a11yproject.com/)
* Check [color contrast ratios](https://developer.mozilla.org/docs/Web/Accessibility/Understanding_WCAG/Perceivable/Color_contrast) between foreground and background elements
* Use [`prefers-reduced-motion`](https://web.dev/prefers-reduced-motion/) when working with animations
[Previous
Architecture
](/docs/architecture)
[Next
Fast Refresh
](/docs/architecture/fast-refresh)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"3d2d47013d01658a9dd7514c29fdd76b\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/generateBuildId | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [
generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/generateBuildId.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)generateBuildId
generateBuildId
===============
Next.js generates an ID during `next build` to identify which version of your application is being served. The same build should be used and boot up multiple containers.
If you are rebuilding for each stage of your environment, you will need to generate a consistent build ID to use between containers. Use the `generateBuildId` command in `next.config.js`:
next.config.js
module.exports = {
generateBuildId: async () => {
// This could be anything, using the latest git hash
return process.env.GIT_HASH
},
}
[Previous
exportPathMap
](/docs/pages/api-reference/next-config-js/exportPathMap)
[Next
generateEtags
](/docs/pages/api-reference/next-config-js/generateEtags)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"8e4d5a33c4240a6117638e1d678cb5df\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/headers | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [
headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Header Overriding Behavior](#header-overriding-behavior)
* [Path Matching](#path-matching)
* [Wildcard Path Matching](#wildcard-path-matching)
* [Regex Path Matching](#regex-path-matching)
* [Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
* [Headers with basePath support](#headers-with-basepath-support)
* [Headers with i18n support](#headers-with-i18n-support)
* [Cache-Control](#cache-control)
* [Options](#options)
* [CORS](#cors)
* [X-DNS-Prefetch-Control](#x-dns-prefetch-control)
* [Strict-Transport-Security](#strict-transport-security)
* [X-Frame-Options](#x-frame-options)
* [Permissions-Policy](#permissions-policy)
* [X-Content-Type-Options](#x-content-type-options)
* [Referrer-Policy](#referrer-policy)
* [Content-Security-Policy](#content-security-policy)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/headers.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)headers
headers
=======
Headers allow you to set custom HTTP headers on the response to an incoming request on a given path.
To set custom HTTP headers you can use the `headers` key in `next.config.js`:
next.config.js
module.exports = {
async headers() {
return [
{
source: '/about',
headers: [
{
key: 'x-custom-header',
value: 'my custom header value',
},
{
key: 'x-another-custom-header',
value: 'my other custom header value',
},
],
},
]
},
}
`headers` is an async function that expects an array to be returned holding objects with `source` and `headers` properties:
* `source` is the incoming request path pattern.
* `headers` is an array of response header objects, with `key` and `value` properties.
* `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only.
* `locale`: `false` or `undefined` - whether the locale should not be included when matching.
* `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
* `missing` is an array of [missing objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
Headers are checked before the filesystem which includes pages and `/public` files.
[Header Overriding Behavior](#header-overriding-behavior)
---------------------------------------------------------
If two headers match the same path and set the same header key, the last header key will override the first. Using the below headers, the path `/hello` will result in the header `x-hello` being `world` due to the last header value set being `world`.
next.config.js
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'x-hello',
value: 'there',
},
],
},
{
source: '/hello',
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
]
},
}
[Path Matching](#path-matching)
-------------------------------
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):
next.config.js
module.exports = {
async headers() {
return [
{
source: '/blog/:slug',
headers: [
{
key: 'x-slug',
value: ':slug', // Matched parameters can be used in the value
},
{
key: 'x-slug-:slug', // Matched parameters can be used in the key
value: 'my other custom header value',
},
],
},
]
},
}
### [Wildcard Path Matching](#wildcard-path-matching)
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:
next.config.js
module.exports = {
async headers() {
return [
{
source: '/blog/:slug*',
headers: [
{
key: 'x-slug',
value: ':slug*', // Matched parameters can be used in the value
},
{
key: 'x-slug-:slug*', // Matched parameters can be used in the key
value: 'my other custom header value',
},
],
},
]
},
}
### [Regex Path Matching](#regex-path-matching)
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
next.config.js
module.exports = {
async headers() {
return [
{
source: '/blog/:post(\\d{1,})',
headers: [
{
key: 'x-post',
value: ':post',
},
],
},
]
},
}
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
next.config.js
module.exports = {
async headers() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
headers: [
{
key: 'x-header',
value: 'value',
},
],
},
]
},
}
[Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
-----------------------------------------------------------------------
To only apply a header when header, cookie, or query values also match the `has` field or don't match the `missing` field can be used. Both the `source` and all `has` items must match and all `missing` items must not match for the header to be applied.
`has` and `missing` items can have the following fields:
* `type`: `String` - must be either `header`, `cookie`, `host`, or `query`.
* `key`: `String` - the key from the selected type to match against.
* `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.
next.config.js
module.exports = {
async headers() {
return [
// if the header `x-add-header` is present,
// the `x-another-header` header will be applied
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-add-header',
},
],
headers: [
{
key: 'x-another-header',
value: 'hello',
},
],
},
// if the header `x-no-header` is not present,
// the `x-another-header` header will be applied
{
source: '/:path*',
missing: [
{
type: 'header',
key: 'x-no-header',
},
],
headers: [
{
key: 'x-another-header',
value: 'hello',
},
],
},
// if the source, query, and cookie are matched,
// the `x-authorized` header will be applied
{
source: '/specific/:path*',
has: [
{
type: 'query',
key: 'page',
// the page value will not be available in the
// header key/values since value is provided and
// doesn't use a named capture group e.g. (?<page>home)
value: 'home',
},
{
type: 'cookie',
key: 'authorized',
value: 'true',
},
],
headers: [
{
key: 'x-authorized',
value: ':authorized',
},
],
},
// if the header `x-authorized` is present and
// contains a matching value, the `x-another-header` will be applied
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-authorized',
value: '(?<authorized>yes|true)',
},
],
headers: [
{
key: 'x-another-header',
value: ':authorized',
},
],
},
// if the host is `example.com`,
// this header will be applied
{
source: '/:path*',
has: [
{
type: 'host',
value: 'example.com',
},
],
headers: [
{
key: 'x-another-header',
value: ':authorized',
},
],
},
]
},
}
[Headers with basePath support](#headers-with-basepath-support)
---------------------------------------------------------------
When leveraging [`basePath` support](/docs/app/api-reference/next-config-js/basePath) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header:
next.config.js
module.exports = {
basePath: '/docs',
async headers() {
return [
{
source: '/with-basePath', // becomes /docs/with-basePath
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
source: '/without-basePath', // is not modified since basePath: false is set
headers: [
{
key: 'x-hello',
value: 'world',
},
],
basePath: false,
},
]
},
}
[Headers with i18n support](#headers-with-i18n-support)
-------------------------------------------------------
When leveraging [`i18n` support](/docs/pages/building-your-application/routing/internationalization) with headers each `source` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the header. If `locale: false` is used you must prefix the `source` with a locale for it to be matched correctly.
next.config.js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},
async headers() {
return [
{
source: '/with-locale', // automatically handles all locales
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
locale: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
// this matches '/' since `en` is the defaultLocale
source: '/en',
locale: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
// this gets converted to /(en|fr|de)/(.*) so will not match the top-level
// `/` or `/fr` routes like /:path* would
source: '/(.*)',
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
]
},
}
[Cache-Control](#cache-control)
-------------------------------
You cannot set `Cache-Control` headers in `next.config.js` for pages or assets, as these headers will be overwritten in production to ensure that responses and static assets are cached effectively.
If you need to revalidate the cache of a page that has been [statically generated](/docs/pages/building-your-application/rendering/static-site-generation), you can do so by setting the `revalidate` prop in the page's [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) function.
You can set the `Cache-Control` header in your [API Routes](/docs/pages/building-your-application/routing/api-routes) by using the `res.setHeader` method:
pages/api/hello.ts
TypeScript
JavaScriptTypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
type ResponseData = {
message: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<ResponseData>
) {
res.setHeader('Cache-Control', 's-maxage=86400')
res.status(200).json({ message: 'Hello from Next.js!' })
}
[Options](#options)
-------------------
### [CORS](#cors)
[Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/docs/Web/HTTP/CORS) is a security feature that allows you to control which sites can access your resources. You can set the `Access-Control-Allow-Origin` header to allow a specific origin to access your API Endpoints.
async headers() {
return [
{
source: "/api/:path*",
headers: [
{
key: "Access-Control-Allow-Origin",
value: "*", // Set your origin
},
{
key: "Access-Control-Allow-Methods",
value: "GET, POST, PUT, DELETE, OPTIONS",
},
{
key: "Access-Control-Allow-Headers",
value: "Content-Type, Authorization",
},
],
},
];
},
### [X-DNS-Prefetch-Control](#x-dns-prefetch-control)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control) controls DNS prefetching, allowing browsers to proactively perform domain name resolution on external links, images, CSS, JavaScript, and more. This prefetching is performed in the background, so the [DNS](https://developer.mozilla.org/docs/Glossary/DNS) is more likely to be resolved by the time the referenced items are needed. This reduces latency when the user clicks a link.
{
key: 'X-DNS-Prefetch-Control',
value: 'on'
}
### [Strict-Transport-Security](#strict-transport-security)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security) informs browsers it should only be accessed using HTTPS, instead of using HTTP. Using the configuration below, all present and future subdomains will use HTTPS for a `max-age` of 2 years. This blocks access to pages or subdomains that can only be served over HTTP.
If you're deploying to [Vercel](https://vercel.com/docs/concepts/edge-network/headers#strict-transport-security?utm_source=next-site&utm_medium=docs&utm_campaign=next-website), this header is not necessary as it's automatically added to all deployments unless you declare `headers` in your `next.config.js`.
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload'
}
### [X-Frame-Options](#x-frame-options)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Frame-Options) indicates whether the site should be allowed to be displayed within an `iframe`. This can prevent against clickjacking attacks.
**This header has been superseded by CSP's `frame-ancestors` option**, which has better support in modern browsers (see [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy) for configuration details).
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN'
}
### [Permissions-Policy](#permissions-policy)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Permissions-Policy) allows you to control which features and APIs can be used in the browser. It was previously named `Feature-Policy`.
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=(), browsing-topics=()'
}
### [X-Content-Type-Options](#x-content-type-options)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Content-Type-Options) prevents the browser from attempting to guess the type of content if the `Content-Type` header is not explicitly set. This can prevent XSS exploits for websites that allow users to upload and share files.
For example, a user trying to download an image, but having it treated as a different `Content-Type` like an executable, which could be malicious. This header also applies to downloading browser extensions. The only valid value for this header is `nosniff`.
{
key: 'X-Content-Type-Options',
value: 'nosniff'
}
### [Referrer-Policy](#referrer-policy)
[This header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Referrer-Policy) controls how much information the browser includes when navigating from the current website (origin) to another.
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin'
}
### [Content-Security-Policy](#content-security-policy)
Learn more about adding a [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy) to your application.
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.3.0`
`missing` added.
`v10.2.0`
`has` added.
`v9.5.0`
Headers added.
[Previous
generateEtags
](/docs/pages/api-reference/next-config-js/generateEtags)
[Next
httpAgentOptions
](/docs/pages/api-reference/next-config-js/httpAgentOptions)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"dab50c1c63e0878d062ba50be4df2852\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture/fast-refresh | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [How It Works](#how-it-works)
* [Error Resilience](#error-resilience)
* [Syntax Errors](#syntax-errors)
* [Runtime Errors](#runtime-errors)
* [Limitations](#limitations)
* [Tips](#tips)
* [Fast Refresh and Hooks](#fast-refresh-and-hooks)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/fast-refresh.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Architecture](/docs/architecture)Fast Refresh
Fast Refresh
============
Fast Refresh is a Next.js feature that gives you instantaneous feedback on edits made to your React components. Fast Refresh is enabled by default in all Next.js applications on **9.4 or newer**. With Next.js Fast Refresh enabled, most edits should be visible within a second, **without losing component state**.
[How It Works](#how-it-works)
-----------------------------
* If you edit a file that **only exports React component(s)**, Fast Refresh will update the code only for that file, and re-render your component. You can edit anything in that file, including styles, rendering logic, event handlers, or effects.
* If you edit a file with exports that _aren't_ React components, Fast Refresh will re-run both that file, and the other files importing it. So if both `Button.js` and `Modal.js` import `theme.js`, editing `theme.js` will update both components.
* Finally, if you **edit a file** that's **imported by files outside of the React tree**, Fast Refresh **will fall back to doing a full reload**. You might have a file which renders a React component but also exports a value that is imported by a **non-React component**. For example, maybe your component also exports a constant, and a non-React utility file imports it. In that case, consider migrating the constant to a separate file and importing it into both files. This will re-enable Fast Refresh to work. Other cases can usually be solved in a similar way.
[Error Resilience](#error-resilience)
-------------------------------------
### [Syntax Errors](#syntax-errors)
If you make a syntax error during development, you can fix it and save the file again. The error will disappear automatically, so you won't need to reload the app. **You will not lose component state**.
### [Runtime Errors](#runtime-errors)
If you make a mistake that leads to a runtime error inside your component, you'll be greeted with a contextual overlay. Fixing the error will automatically dismiss the overlay, without reloading the app.
Component state will be retained if the error did not occur during rendering. If the error did occur during rendering, React will remount your application using the updated code.
If you have [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) in your app (which is a good idea for graceful failures in production), they will retry rendering on the next edit after a rendering error. This means having an error boundary can prevent you from always getting reset to the root app state. However, keep in mind that error boundaries shouldn't be _too_ granular. They are used by React in production, and should always be designed intentionally.
[Limitations](#limitations)
---------------------------
Fast Refresh tries to preserve local React state in the component you're editing, but only if it's safe to do so. Here's a few reasons why you might see local state being reset on every edit to a file:
* Local state is not preserved for class components (only function components and Hooks preserve state).
* The file you're editing might have _other_ exports in addition to a React component.
* Sometimes, a file would export the result of calling a higher-order component like `HOC(WrappedComponent)`. If the returned component is a class, its state will be reset.
* Anonymous arrow functions like `export default () => <div />;` cause Fast Refresh to not preserve local component state. For large codebases you can use our [`name-default-component` codemod](/docs/pages/building-your-application/upgrading/codemods#name-default-component).
As more of your codebase moves to function components and Hooks, you can expect state to be preserved in more cases.
[Tips](#tips)
-------------
* Fast Refresh preserves React local state in function components (and Hooks) by default.
* Sometimes you might want to _force_ the state to be reset, and a component to be remounted. For example, this can be handy if you're tweaking an animation that only happens on mount. To do this, you can add `// @refresh reset` anywhere in the file you're editing. This directive is local to the file, and instructs Fast Refresh to remount components defined in that file on every edit.
* You can put `console.log` or `debugger;` into the components you edit during development.
* Remember that imports are case sensitive. Both fast and full refresh can fail, when your import doesn't match the actual filename. For example, `'./header'` vs `'./Header'`.
[Fast Refresh and Hooks](#fast-refresh-and-hooks)
-------------------------------------------------
When possible, Fast Refresh attempts to preserve the state of your component between edits. In particular, `useState` and `useRef` preserve their previous values as long as you don't change their arguments or the order of the Hook calls.
Hooks with dependencies—such as `useEffect`, `useMemo`, and `useCallback`—will _always_ update during Fast Refresh. Their list of dependencies will be ignored while Fast Refresh is happening.
For example, when you edit `useMemo(() => x * 2, [x])` to `useMemo(() => x * 10, [x])`, it will re-run even though `x` (the dependency) has not changed. If React didn't do that, your edit wouldn't reflect on the screen!
Sometimes, this can lead to unexpected results. For example, even a `useEffect` with an empty array of dependencies would still re-run once during Fast Refresh.
However, writing code resilient to occasional re-running of `useEffect` is a good practice even without Fast Refresh. It will make it easier for you to introduce new dependencies to it later on and it's enforced by [React Strict Mode](/docs/pages/api-reference/next-config-js/reactStrictMode), which we highly recommend enabling.
[Previous
Accessibility
](/docs/architecture/accessibility)
[Next
Next.js Compiler
](/docs/architecture/nextjs-compiler)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"36ef98309181d57c2de7551a06ffc4fe\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture/nextjs-compiler | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Why SWC?](#why-swc)
* [Supported Features](#supported-features)
* [Styled Components](#styled-components)
* [Jest](#jest)
* [Relay](#relay)
* [Remove React Properties](#remove-react-properties)
* [Remove Console](#remove-console)
* [Legacy Decorators](#legacy-decorators)
* [importSource](#importsource)
* [Emotion](#emotion)
* [Minification](#minification)
* [Module Transpilation](#module-transpilation)
* [Modularize Imports](#modularize-imports)
* [Experimental Features](#experimental-features)
* [SWC Trace profiling](#swc-trace-profiling)
* [SWC Plugins (Experimental)](#swc-plugins-experimental)
* [Unsupported Features](#unsupported-features)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/nextjs-compiler.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Architecture](/docs/architecture)Next.js Compiler
Next.js Compiler
================
The Next.js Compiler, written in Rust using [SWC](https://swc.rs/), allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual files and Terser for minifying output bundles.
Compilation using the Next.js Compiler is 17x faster than Babel and enabled by default since Next.js version 12. If you have an existing Babel configuration or are using [unsupported features](#unsupported-features), your application will opt-out of the Next.js Compiler and continue using Babel.
[Why SWC?](#why-swc)
--------------------
[SWC](https://swc.rs/) is an extensible Rust-based platform for the next generation of fast developer tools.
SWC can be used for compilation, minification, bundling, and more – and is designed to be extended. It's something you can call to perform code transformations (either built-in or custom). Running those transformations happens through higher-level tools like Next.js.
We chose to build on SWC for a few reasons:
* **Extensibility:** SWC can be used as a Crate inside Next.js, without having to fork the library or workaround design constraints.
* **Performance:** We were able to achieve ~3x faster Fast Refresh and ~5x faster builds in Next.js by switching to SWC, with more room for optimization still in progress.
* **WebAssembly:** Rust's support for WASM is essential for supporting all possible platforms and taking Next.js development everywhere.
* **Community:** The Rust community and ecosystem are amazing and still growing.
[Supported Features](#supported-features)
-----------------------------------------
### [Styled Components](#styled-components)
We're working to port `babel-plugin-styled-components` to the Next.js Compiler.
First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `next.config.js` file:
next.config.js
module.exports = {
compiler: {
styledComponents: true,
},
}
For advanced use cases, you can configure individual properties for styled-components compilation.
> Note: `minify`, `transpileTemplateLiterals` and `pure` are not yet implemented. You can follow the progress [here](https://github.com/vercel/next.js/issues/30802). `ssr` and `displayName` transforms are the main requirement for using `styled-components` in Next.js.
next.config.js
module.exports = {
compiler: {
// see https://styled-components.com/docs/tooling#babel-plugin for more info on the options.
styledComponents: {
// Enabled by default in development, disabled in production to reduce file size,
// setting this will override the default for all environments.
displayName?: boolean,
// Enabled by default.
ssr?: boolean,
// Enabled by default.
fileName?: boolean,
// Empty by default.
topLevelImportPaths?: string[],
// Defaults to ["index"].
meaninglessFileNames?: string[],
// Enabled by default.
cssProp?: boolean,
// Empty by default.
namespace?: string,
// Not supported yet.
minify?: boolean,
// Not supported yet.
transpileTemplateLiterals?: boolean,
// Not supported yet.
pure?: boolean,
},
},
}
### [Jest](#jest)
The Next.js Compiler transpiles your tests and simplifies configuring Jest together with Next.js including:
* Auto mocking of `.css`, `.module.css` (and their `.scss` variants), and image imports
* Automatically sets up `transform` using SWC
* Loading `.env` (and all variants) into `process.env`
* Ignores `node_modules` from test resolving and transforms
* Ignoring `.next` from test resolving
* Loads `next.config.js` for flags that enable experimental SWC transforms
First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `jest.config.js` file:
jest.config.js
const nextJest = require('next/jest')
// Providing the path to your Next.js app which will enable loading next.config.js and .env files
const createJestConfig = nextJest({ dir: './' })
// Any custom config you want to pass to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
}
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js configuration, which is async
module.exports = createJestConfig(customJestConfig)
### [Relay](#relay)
To enable [Relay](https://relay.dev/) support:
next.config.js
module.exports = {
compiler: {
relay: {
// This should match relay.config.js
src: './',
artifactDirectory: './__generated__',
language: 'typescript',
eagerEsModules: false,
},
},
}
> **Good to know**: In Next.js, all JavaScript files in `pages` directory are considered routes. So, for `relay-compiler` you'll need to specify `artifactDirectory` configuration settings outside of the `pages`, otherwise `relay-compiler` will generate files next to the source file in the `__generated__` directory, and this file will be considered a route, which will break production builds.
### [Remove React Properties](#remove-react-properties)
Allows to remove JSX properties. This is often used for testing. Similar to `babel-plugin-react-remove-properties`.
To remove properties matching the default regex `^data-test`:
next.config.js
module.exports = {
compiler: {
reactRemoveProperties: true,
},
}
To remove custom properties:
next.config.js
module.exports = {
compiler: {
// The regexes defined here are processed in Rust so the syntax is different from
// JavaScript `RegExp`s. See https://docs.rs/regex.
reactRemoveProperties: { properties: ['^data-custom$'] },
},
}
### [Remove Console](#remove-console)
This transform allows for removing all `console.*` calls in application code (not `node_modules`). Similar to `babel-plugin-transform-remove-console`.
Remove all `console.*` calls:
next.config.js
module.exports = {
compiler: {
removeConsole: true,
},
}
Remove `console.*` output except `console.error`:
next.config.js
module.exports = {
compiler: {
removeConsole: {
exclude: ['error'],
},
},
}
### [Legacy Decorators](#legacy-decorators)
Next.js will automatically detect `experimentalDecorators` in `jsconfig.json` or `tsconfig.json`. Legacy decorators are commonly used with older versions of libraries like `mobx`.
This flag is only supported for compatibility with existing applications. We do not recommend using legacy decorators in new applications.
First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `jsconfig.json` or `tsconfig.json` file:
{
"compilerOptions": {
"experimentalDecorators": true
}
}
### [importSource](#importsource)
Next.js will automatically detect `jsxImportSource` in `jsconfig.json` or `tsconfig.json` and apply that. This is commonly used with libraries like [Theme UI](https://theme-ui.com).
First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `jsconfig.json` or `tsconfig.json` file:
{
"compilerOptions": {
"jsxImportSource": "theme-ui"
}
}
### [Emotion](#emotion)
We're working to port `@emotion/babel-plugin` to the Next.js Compiler.
First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `next.config.js` file:
next.config.js
module.exports = {
compiler: {
emotion: boolean | {
// default is true. It will be disabled when build type is production.
sourceMap?: boolean,
// default is 'dev-only'.
autoLabel?: 'never' | 'dev-only' | 'always',
// default is '[local]'.
// Allowed values: `[local]` `[filename]` and `[dirname]`
// This option only works when autoLabel is set to 'dev-only' or 'always'.
// It allows you to define the format of the resulting label.
// The format is defined via string where variable parts are enclosed in square brackets [].
// For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.
labelFormat?: string,
// default is undefined.
// This option allows you to tell the compiler what imports it should
// look at to determine what it should transform so if you re-export
// Emotion's exports, you can still use transforms.
importMap?: {
[packageName: string]: {
[exportName: string]: {
canonicalImport?: [string, string],
styledBaseImport?: [string, string],
}
}
},
},
},
}
### [Minification](#minification)
Next.js' swc compiler is used for minification by default since v13. This is 7x faster than Terser.
If Terser is still needed for any reason this can be configured.
next.config.js
module.exports = {
swcMinify: false,
}
### [Module Transpilation](#module-transpilation)
Next.js can automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (`node_modules`). This replaces the `next-transpile-modules` package.
next.config.js
module.exports = {
transpilePackages: ['@acme/ui', 'lodash-es'],
}
### [Modularize Imports](#modularize-imports)
This option has been superseded by [`optimizePackageImports`](/docs/app/api-reference/next-config-js/optimizePackageImports) in Next.js 13.5. We recommend upgrading to use the new option that does not require manual configuration of import paths.
[Experimental Features](#experimental-features)
-----------------------------------------------
### [SWC Trace profiling](#swc-trace-profiling)
You can generate SWC's internal transform traces as chromium's [trace event format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview?mode=html#%21=).
next.config.js
module.exports = {
experimental: {
swcTraceProfiling: true,
},
}
Once enabled, swc will generate trace named as `swc-trace-profile-${timestamp}.json` under `.next/`. Chromium's trace viewer (chrome://tracing/, [https://ui.perfetto.dev/](https://ui.perfetto.dev/)), or compatible flamegraph viewer ([https://www.speedscope.app/](https://www.speedscope.app/)) can load & visualize generated traces.
### [SWC Plugins (Experimental)](#swc-plugins-experimental)
You can configure swc's transform to use SWC's experimental plugin support written in wasm to customize transformation behavior.
next.config.js
module.exports = {
experimental: {
swcPlugins: [
[
'plugin',
{
...pluginOptions,
},
],
],
},
}
`swcPlugins` accepts an array of tuples for configuring plugins. A tuple for the plugin contains the path to the plugin and an object for plugin configuration. The path to the plugin can be an npm module package name or an absolute path to the `.wasm` binary itself.
[Unsupported Features](#unsupported-features)
---------------------------------------------
When your application has a `.babelrc` file, Next.js will automatically fall back to using Babel for transforming individual files. This ensures backwards compatibility with existing applications that leverage custom Babel plugins.
If you're using a custom Babel setup, [please share your configuration](https://github.com/vercel/next.js/discussions/30174). We're working to port as many commonly used Babel transformations as possible, as well as supporting plugins in the future.
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.1.0`
[Module Transpilation](https://nextjs.org/blog/next-13-1#built-in-module-transpilation-stable) and [Modularize Imports](https://nextjs.org/blog/next-13-1#import-resolution-for-smaller-bundles) stable.
`v13.0.0`
SWC Minifier enabled by default.
`v12.3.0`
SWC Minifier [stable](https://nextjs.org/blog/next-12-3#swc-minifier-stable).
`v12.2.0`
[SWC Plugins](#swc-plugins-experimental) experimental support added.
`v12.1.0`
Added support for Styled Components, Jest, Relay, Remove React Properties, Legacy Decorators, Remove Console, and jsxImportSource.
`v12.0.0`
Next.js Compiler [introduced](https://nextjs.org/blog/next-12).
[Previous
Fast Refresh
](/docs/architecture/fast-refresh)
[Next
Supported Browsers
](/docs/architecture/supported-browsers)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"fb7d5b5025972e22e81388262fd82044\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture/turbopack | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Usage](#usage)
* [Supported features](#supported-features)
* [Unsupported features](#unsupported-features)
* [Generating Trace Files](#generating-trace-files)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/turbopack.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Architecture](/docs/architecture)Turbopack
Turbopack
=========
[Turbopack](https://turbo.build/pack) (beta) is an incremental bundler optimized for JavaScript and TypeScript, written in Rust, and built into Next.js.
[Usage](#usage)
---------------
Turbopack can be used in Next.js in both the `pages` and `app` directories for faster local development. To enable Turbopack, use the `--turbo` flag when running the Next.js development server.
package.json
{
"scripts": {
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
}
[Supported features](#supported-features)
-----------------------------------------
Turbopack in Next.js requires zero-configuration for most users and can be extended for more advanced use cases. To learn more about the currently supported features for Turbopack, view the [API Reference](/docs/app/api-reference/next-config-js/turbo).
[Unsupported features](#unsupported-features)
---------------------------------------------
Turbopack currently only supports `next dev` and does not support `next build`. We are currently working on support for builds as we move closer towards stability.
These features are currently not supported:
* [`webpack()`](/docs/app/api-reference/next-config-js/webpack) configuration in `next.config.js`
* Turbopack replaces Webpack, this means that webpack configuration is not supported.
* To configure Turbopack, [see the documentation](/docs/app/api-reference/next-config-js/turbo).
* A subset of [Webpack loaders](/docs/app/api-reference/next-config-js/turbo#webpack-loaders) are supported in Turbopack.
* Babel (`.babelrc`)
* Turbopack leverages the [SWC](/docs/architecture/nextjs-compiler#why-swc) compiler for all transpilation and optimizations. This means that Babel is not included by default.
* If you have a `.babelrc` file, you might no longer need it because Next.js includes common Babel plugins as SWC transforms that can be enabled. You can read more about this in the [compiler documentation](docs/architecture/nextjs-compiler#supported-features).
* If you still need to use Babel after verifying your particular use case is not covered, you can leverage Turbopack's [support for custom webpack loaders](/docs/app/api-reference/next-config-js/turbo#webpack-loaders) to include `babel-loader`.
* Creating a root layout automatically in App Router.
* This behavior is currently not supported since it changes input files, instead, an error will be shown for you manually add a root layout in the desired location.
* `@next/font` (legacy font support).
* `@next/font` is deprecated in favor of `next/font`. [`next/font`](/docs/app/building-your-application/optimizing/fonts) is fully supported with Turbopack.
* `new Worker('file', import.meta.url)`.
* We are planning to implement this in the future.
* [Relay transforms](/docs/architecture/nextjs-compiler#relay)
* We are planning to implement this in the future.
* `experimental.nextScriptWorkers`
* We are planning to implement this in the future.
* [AMP](/docs/pages/building-your-application/configuring/amp).
* We are currently not planning to support AMP in Next.js with Turbopack.
* Yarn PnP
* We are currently not planning to support Yarn PnP in Next.js with Turbopack.
* [`experimental.urlImports`](/docs/app/api-reference/next-config-js/urlImports)
* We are currently not planning to support `experimental.urlImports` in Next.js with Turbopack.
[Generating Trace Files](#generating-trace-files)
-------------------------------------------------
Trace files allow the Next.js team to investigate and improve performance metrics and memory usage. To generate a trace file, append `NEXT_TURBOPACK_TRACING=1` to the `next dev --turbo` command, this will generate a `.next/trace.log` file.
When reporting issues related to Turbopack performance and memory usage, please include the trace file in your [GitHub](https://github.com/vercel/next.js) issue.
[Previous
Supported Browsers
](/docs/architecture/supported-browsers)
[Next
Community
](/docs/community)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"6ca4a9a0c3d6afefa0e3eb44c60cb363\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/httpAgentOptions | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [
httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/httpAgentOptions.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)httpAgentOptions
httpAgentOptions
================
In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [undici](/docs/architecture/supported-browsers#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/docs/Web/HTTP/Headers/Keep-Alive) by default.
To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config:
next.config.js
module.exports = {
httpAgentOptions: {
keepAlive: false,
},
}
[Previous
headers
](/docs/pages/api-reference/next-config-js/headers)
[Next
images
](/docs/pages/api-reference/next-config-js/images)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"839f21ab22848f083fbb9cffd730119f\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/architecture/supported-browsers | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Browserslist](#browserslist)
* [Polyfills](#polyfills)
* [Custom Polyfills](#custom-polyfills)
* [JavaScript Language Features](#javascript-language-features)
* [TypeScript Features](#typescript-features)
* [Customizing Babel Config (Advanced)](#customizing-babel-config-advanced)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/04-architecture/supported-browsers.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Architecture](/docs/architecture)Supported Browsers
Supported Browsers
==================
Next.js supports **modern browsers** with zero configuration.
* Chrome 64+
* Edge 79+
* Firefox 67+
* Opera 51+
* Safari 12+
[Browserslist](#browserslist)
-----------------------------
If you would like to target specific browsers or features, Next.js supports [Browserslist](https://browsersl.ist) configuration in your `package.json` file. Next.js uses the following Browserslist configuration by default:
package.json
{
"browserslist": [
"chrome 64",
"edge 79",
"firefox 67",
"opera 51",
"safari 12"
]
}
[Polyfills](#polyfills)
-----------------------
We inject [widely used polyfills](https://github.com/vercel/next.js/blob/canary/packages/next-polyfill-nomodule/src/index.js), including:
* [**fetch()**](https://developer.mozilla.org/docs/Web/API/Fetch_API) — Replacing: `whatwg-fetch` and `unfetch`.
* [**URL**](https://developer.mozilla.org/docs/Web/API/URL) — Replacing: the [`url` package (Node.js API)](https://nodejs.org/api/url.html).
* [**Object.assign()**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) — Replacing: `object-assign`, `object.assign`, and `core-js/object/assign`.
If any of your dependencies include these polyfills, they’ll be eliminated automatically from the production build to avoid duplication.
In addition, to reduce bundle size, Next.js will only load these polyfills for browsers that require them. The majority of the web traffic globally will not download these polyfills.
### [Custom Polyfills](#custom-polyfills)
If your own code or any external npm dependencies require features not supported by your target browsers (such as IE 11), you need to add polyfills yourself.
In this case, you should add a top-level import for the **specific polyfill** you need in your [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) or the individual component.
[JavaScript Language Features](#javascript-language-features)
-------------------------------------------------------------
Next.js allows you to use the latest JavaScript features out of the box. In addition to [ES6 features](https://github.com/lukehoban/es6features), Next.js also supports:
* [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017)
* [Object Rest/Spread Properties](https://github.com/tc39/proposal-object-rest-spread) (ES2018)
* [Dynamic `import()`](https://github.com/tc39/proposal-dynamic-import) (ES2020)
* [Optional Chaining](https://github.com/tc39/proposal-optional-chaining) (ES2020)
* [Nullish Coalescing](https://github.com/tc39/proposal-nullish-coalescing) (ES2020)
* [Class Fields](https://github.com/tc39/proposal-class-fields) and [Static Properties](https://github.com/tc39/proposal-static-class-features) (ES2022)
* and more!
### [TypeScript Features](#typescript-features)
Next.js has built-in TypeScript support. [Learn more here](/docs/pages/building-your-application/configuring/typescript).
### [Customizing Babel Config (Advanced)](#customizing-babel-config-advanced)
You can customize babel configuration. [Learn more here](/docs/pages/building-your-application/configuring/babel).
[Previous
Next.js Compiler
](/docs/architecture/nextjs-compiler)
[Next
Turbopack
](/docs/architecture/turbopack)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"a9ce3dfe9d97ad6f7e432540a78f4a14\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/learn/react-foundations | React Foundations
=================
To effectively learn Next.js, it helps to be familiar with JavaScript, React, and related web development concepts. But JavaScript and React are vast topics. How do you know when you're ready to start using Next.js?
Welcome to the React Foundations course! This beginner-friendly, example-led course will guide you through the prerequisite knowledge for Next.js. You will build a simple project step-by-step; starting with a JavaScript application, then migrating it to React and Next.js.
Each section builds on the previous one, so you can choose where to start depending on what you already know.
### [Prerequisite knowledge](#prerequisite-knowledge)
This tutorial assumes knowledge of HTML, CSS, JavaScript, and no knowledge of React. If you're already familiar with React, you can skip to the [From React to Next.js](/learn/react-foundations/from-react-to-nextjs) chapter or take [Dashboard App](/learn/dashboard-app) course.
### [System requirements](#system-requirements)
Before you start this course, make sure you have the following installed:
* Node.js 20.12.0 or later installed.
* Operating systems: macOS, Windows (including WSL), or Linux.
* VSCode or another text editor of your choice.
### [Join the conversation](#join-the-conversation)
If you have questions about anything related to Next.js or this course, you're welcome to ask our community on [Discord](https://discord.gg/Q3AsD4efFC).
Ready to get started?
---------------------
Now that you've been introduced to the course, let's dive in.
Next Up
1: About React and Next.js
Learn what React and Next.js are, and how they can help you build modern web applications.
[Start Chapter 1](/learn/react-foundations/what-is-react-and-nextjs)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"d472dcffc8a046627287569a3d3908b8\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/images | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [
images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Example Loader Configuration](#example-loader-configuration)
* [Akamai](#akamai)
* [AWS CloudFront](#aws-cloudfront)
* [Cloudinary](#cloudinary)
* [Cloudflare](#cloudflare)
* [Contentful](#contentful)
* [Fastly](#fastly)
* [Gumlet](#gumlet)
* [ImageEngine](#imageengine)
* [Imgix](#imgix)
* [Thumbor](#thumbor)
* [Sanity](#sanity)
* [Sirv](#sirv)
* [Supabase](#supabase)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/images.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)images
images
======
If you want to use a cloud provider to optimize images instead of using the Next.js built-in Image Optimization API, you can configure `next.config.js` with the following:
next.config.js
module.exports = {
images: {
loader: 'custom',
loaderFile: './my/image/loader.js',
},
}
This `loaderFile` must point to a file relative to the root of your Next.js application. The file must export a default function that returns a string, for example:
my/image/loader.js
export default function myImageLoader({ src, width, quality }) {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
Alternatively, you can use the [`loader` prop](/docs/pages/api-reference/components/image#loader) to pass the function to each instance of `next/image`.
To learn more about configuring the behavior of the built-in [Image Optimization API](/docs/pages/building-your-application/optimizing/images) and the [Image Component](/docs/pages/api-reference/components/image), see [Image Configuration Options](/docs/pages/api-reference/components/image#configuration-options) for available options.
[Example Loader Configuration](#example-loader-configuration)
-------------------------------------------------------------
* [Akamai](#akamai)
* [AWS CloudFront](#aws-cloudfront)
* [Cloudinary](#cloudinary)
* [Cloudflare](#cloudflare)
* [Contentful](#contentful)
* [Fastly](#fastly)
* [Gumlet](#gumlet)
* [ImageEngine](#imageengine)
* [Imgix](#imgix)
* [Thumbor](#thumbor)
* [Sanity](#sanity)
* [Sirv](#sirv)
* [Supabase](#supabase)
### [Akamai](#akamai)
// Docs: https://techdocs.akamai.com/ivm/reference/test-images-on-demand
export default function akamaiLoader({ src, width, quality }) {
return `https://example.com/${src}?imwidth=${width}`
}
### [AWS CloudFront](#aws-cloudfront)
// Docs: https://aws.amazon.com/developer/application-security-performance/articles/image-optimization
export default function cloudfrontLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
url.searchParams.set('format', 'auto')
url.searchParams.set('width', width.toString())
url.searchParams.set('quality', (quality || 75).toString())
return url.href
### [Cloudinary](#cloudinary)
// Demo: https://res.cloudinary.com/demo/image/upload/w_300,c_limit,q_auto/turtles.jpg
export default function cloudinaryLoader({ src, width, quality }) {
const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`]
return `https://example.com/${params.join(',')}${src}`
}
### [Cloudflare](#cloudflare)
// Docs: https://developers.cloudflare.com/images/url-format
export default function cloudflareLoader({ src, width, quality }) {
const params = [`width=${width}`, `quality=${quality || 75}`, 'format=auto']
return `https://example.com/cdn-cgi/image/${params.join(',')}/${src}`
}
### [Contentful](#contentful)
// Docs: https://www.contentful.com/developers/docs/references/images-api/
export default function contentfulLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
url.searchParams.set('fm', 'webp')
url.searchParams.set('w', width.toString())
url.searchParams.set('q', (quality || 75).toString())
return url.href
}
### [Fastly](#fastly)
// Docs: https://developer.fastly.com/reference/io/
export default function fastlyLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
url.searchParams.set('auto', 'webp')
url.searchParams.set('width', width.toString())
url.searchParams.set('quality', (quality || 75).toString())
return url.href
}
### [Gumlet](#gumlet)
// Docs: https://docs.gumlet.com/reference/image-transform-size
export default function gumletLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
url.searchParams.set('format', 'auto')
url.searchParams.set('w', width.toString())
url.searchParams.set('q', (quality || 75).toString())
return url.href
}
### [ImageEngine](#imageengine)
// Docs: https://support.imageengine.io/hc/en-us/articles/360058880672-Directives
export default function imageengineLoader({ src, width, quality }) {
const compression = 100 - (quality || 50)
const params = [`w_${width}`, `cmpr_${compression}`)]
return `https://example.com${src}?imgeng=/${params.join('/')`
}
### [Imgix](#imgix)
// Demo: https://static.imgix.net/daisy.png?format=auto&fit=max&w=300
export default function imgixLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
const params = url.searchParams
params.set('auto', params.getAll('auto').join(',') || 'format')
params.set('fit', params.get('fit') || 'max')
params.set('w', params.get('w') || width.toString())
params.set('q', (quality || 50).toString())
return url.href
}
### [Thumbor](#thumbor)
// Docs: https://thumbor.readthedocs.io/en/latest/
export default function thumborLoader({ src, width, quality }) {
const params = [`${width}x0`, `filters:quality(${quality || 75})`]
return `https://example.com${params.join('/')}${src}`
}
### [Sanity](#sanity)
// Docs: https://www.sanity.io/docs/image-urls
export default function sanityLoader({ src, width, quality }) {
const prj = 'zp7mbokg'
const dataset = 'production'
const url = new URL(`https://cdn.sanity.io/images/${prj}/${dataset}${src}`)
url.searchParams.set('auto', 'format')
url.searchParams.set('fit', 'max')
url.searchParams.set('w', width.toString())
if (quality) {
url.searchParams.set('q', quality.toString())
}
return url.href
}
### [Sirv](#sirv)
// Docs: https://sirv.com/help/articles/dynamic-imaging/
export default function sirvLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
const params = url.searchParams
params.set('format', params.getAll('format').join(',') || 'optimal')
params.set('w', params.get('w') || width.toString())
params.set('q', (quality || 85).toString())
return url.href
}
### [Supabase](#supabase)
// Docs: https://supabase.com/docs/guides/storage/image-transformations#nextjs-loader
export default function supabaseLoader({ src, width, quality }) {
const url = new URL(`https://example.com${src}`)
url.searchParams.set('width', width.toString())
url.searchParams.set('quality', (quality || 75).toString())
return url.href
}
[Previous
httpAgentOptions
](/docs/pages/api-reference/next-config-js/httpAgentOptions)
[Next
instrumentationHook
](/docs/pages/api-reference/next-config-js/instrumentationHook)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"71726c8cc7c78415b92dacf4b79a0270\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/instrumentationHook | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [
instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/instrumentationHook.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)instrumentationHook
instrumentationHook
===================
The experimental `instrumentationHook` option allows you to set up instrumentation via the [`instrumentation` file](/docs/app/api-reference/file-conventions/instrumentation) in your Next.js App.
next.config.js
module.exports = {
experimental: {
instrumentationHook: true,
},
}
[Previous
images
](/docs/pages/api-reference/next-config-js/images)
[Next
onDemandEntries
](/docs/pages/api-reference/next-config-js/onDemandEntries)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"d379e0ac4dc28f3599a9b2cebac8af1b\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/community | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Contributing](#contributing)
* [Discussions](#discussions)
* [Social Media](#social-media)
* [Code of Conduct](#code-of-conduct)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/05-community/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
Next.js Community
=================
With over 5 million weekly downloads, Next.js has a large and active community of developers across the world. Here's how you can get involved in our community:
[Contributing](#contributing)
-----------------------------
There are a couple of ways you can contribute to the development of Next.js:
* [Documentation](/docs/community/contribution-guide): Suggest improvements or even write new sections to help our users understand how to use Next.js.
* [Examples](https://github.com/vercel/next.js/tree/canary/contributing/examples): Help developers integrate Next.js with other tools and services by creating a new example or improving an existing one.
* [Codebase](https://github.com/vercel/next.js/tree/canary/contributing/core): Learn more about the underlying architecture, contribute to bug fixes, errors, and suggest new features.
[Discussions](#discussions)
---------------------------
If you have a question about Next.js, or want to help others, you're always welcome to join the conversation:
* [GitHub Discussions](https://github.com/vercel/next.js/discussions)
* [Discord](https://discord.com/invite/bUG2bvbtHy)
* [Reddit](https://www.reddit.com/r/nextjs)
[Social Media](#social-media)
-----------------------------
Follow Next.js on [Twitter](https://twitter.com/nextjs) for the latest updates, and subscribe to the [Vercel YouTube channel](https://www.youtube.com/@VercelHQ) for Next.js videos.
[Code of Conduct](#code-of-conduct)
-----------------------------------
We believe in creating an inclusive, welcoming community. As such, we ask all members to adhere to our [Code of Conduct](https://github.com/vercel/next.js/blob/canary/CODE_OF_CONDUCT.md). This document outlines our expectations for participant behavior. We invite you to read it and help us maintain a safe and respectful environment.
[
### Contribution Guide
Learn how to contribute to Next.js Documentation
](/docs/community/contribution-guide)
[Previous
Turbopack
](/docs/architecture/turbopack)
[Next
Contribution Guide
](/docs/community/contribution-guide)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"d25e78e3cdda3e5ad53d758e1e3d6d9d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/pageExtensions | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [
pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Including non-page files in the pages directory](#including-non-page-files-in-the-pages-directory)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/pageExtensions.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)pageExtensions
pageExtensions
==============
You can extend the default Page extensions (`.tsx`, `.ts`, `.jsx`, `.js`) used by Next.js. Inside `next.config.js`, add the `pageExtensions` config:
next.config.js
module.exports = {
pageExtensions: ['mdx', 'md', 'jsx', 'js', 'tsx', 'ts'],
}
Changing these values affects _all_ Next.js pages, including the following:
* [`middleware.js`](/docs/pages/building-your-application/routing/middleware)
* [`instrumentation.js`](/docs/pages/building-your-application/optimizing/instrumentation)
* `pages/_document.js`
* `pages/_app.js`
* `pages/api/`
For example, if you reconfigure `.ts` page extensions to `.page.ts`, you would need to rename pages like `middleware.page.ts`, `instrumentation.page.ts`, `_app.page.ts`.
[Including non-page files in the `pages` directory](#including-non-page-files-in-the-pages-directory)
-----------------------------------------------------------------------------------------------------
You can colocate test files or other files used by components in the `pages` directory. Inside `next.config.js`, add the `pageExtensions` config:
next.config.js
module.exports = {
pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
}
Then, rename your pages to have a file extension that includes `.page` (e.g. rename `MyPage.tsx` to `MyPage.page.tsx`). Ensure you rename _all_ Next.js pages, including the files mentioned above.
[Previous
output
](/docs/pages/api-reference/next-config-js/output)
[Next
poweredByHeader
](/docs/pages/api-reference/next-config-js/poweredByHeader)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"26cb9de166e8936fd61847968b67b9c5\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/community/contribution-guide | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Why Contribute?](#why-contribute)
* [How to Contribute](#how-to-contribute)
* [GitHub Workflow](#github-workflow)
* [Writing MDX](#writing-mdx)
* [VSCode](#vscode)
* [Previewing Changes Locally](#previewing-changes-locally)
* [Extensions](#extensions)
* [Review Process](#review-process)
* [File Structure](#file-structure)
* [Metadata](#metadata)
* [Required Fields](#required-fields)
* [Optional Fields](#optional-fields)
* [App and Pages Docs](#app-and-pages-docs)
* [Shared Pages](#shared-pages)
* [Shared Content](#shared-content)
* [Code Blocks](#code-blocks)
* [Language and Filename](#language-and-filename)
* [TS and JS Switcher](#ts-and-js-switcher)
* [Line Highlighting](#line-highlighting)
* [Icons](#icons)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/05-community/01-contribution-guide.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Community](/docs/community)Contribution Guide
Docs Contribution Guide
=======================
Welcome to the Next.js Docs Contribution Guide! We're excited to have you here.
This page provides instructions on how to edit the Next.js documentation. Our goal is to ensure that everyone in the community feels empowered to contribute and improve our docs.
[Why Contribute?](#why-contribute)
----------------------------------
Open-source work is never done, and neither is documentation. Contributing to docs is a good way for beginners to get involved in open-source and for experienced developers to clarify more complex topics while sharing their knowledge with the community.
By contributing to the Next.js docs, you're helping us build a more robust learning resource for all developers. Whether you've found a typo, a confusing section, or you've realized that a particular topic is missing, your contributions are welcomed and appreciated.
[How to Contribute](#how-to-contribute)
---------------------------------------
The docs content can be found on the [Next.js repo](https://github.com/vercel/next.js/tree/canary/docs). To contribute, you can edit the files directly on GitHub or clone the repo and edit the files locally.
### [GitHub Workflow](#github-workflow)
If you're new to GitHub, we recommend reading the [GitHub Open Source Guide](https://opensource.guide/how-to-contribute/#opening-a-pull-request) to learn how to fork a repository, create a branch, and submit a pull request.
> **Good to know**: The underlying docs code lives in a private codebase that is synced to the Next.js public repo. This means that you can't preview the docs locally. However, you'll see your changes on [nextjs.org](https://nextjs.org/docs) after merging a pull request.
### [Writing MDX](#writing-mdx)
The docs are written in [MDX](https://mdxjs.com/), a markdown format that supports JSX syntax. This allows us to embed React components in the docs. See the [GitHub Markdown Guide](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for a quick overview of markdown syntax.
### [VSCode](#vscode)
#### [Previewing Changes Locally](#previewing-changes-locally)
VSCode has a built-in markdown previewer that you can use to see your edits locally. To enable the previewer for MDX files, you'll need to add a configuration option to your user settings.
Open the command palette (`⌘ + ⇧ + P` on Mac or `Ctrl + Shift + P` on Windows) and search from `Preferences: Open User Settings (JSON)`.
Then, add the following line to your `settings.json` file:
settings.json
{
"files.associations": {
"*.mdx": "markdown"
}
}
Next, open the command palette again, and search for `Markdown: Preview File` or `Markdown: Open Preview to the Side`. This will open a preview window where you can see your formatted changes.
#### [Extensions](#extensions)
We also recommend the following extensions for VSCode users:
* [MDX](https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx): Intellisense and syntax highlighting for MDX.
* [Grammarly](https://marketplace.visualstudio.com/items?itemName=znck.grammarly): Grammar and spell checker.
* [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode): Format MDX files on save.
### [Review Process](#review-process)
Once you've submitted your contribution, the Next.js or Developer Experience teams will review your changes, provide feedback, and merge the pull request when it's ready.
Please let us know if you have any questions or need further assistance in your PR's comments. Thank you for contributing to the Next.js docs and being a part of our community!
> **Tip:** Run `pnpm prettier-fix` to run Prettier before submitting your PR.
[File Structure](#file-structure)
---------------------------------
The docs use **file-system routing**. Each folder and files inside [`/docs`](https://github.com/vercel/next.js/tree/canary/docs) represent a route segment. These segments are used to generate the URL paths, navigation, and breadcrumbs.
The file structure reflects the navigation that you see on the site, and by default, navigation items are sorted alphabetically. However, we can change the order of the items by prepending a two-digit number (`00-`) to the folder or file name.
For example, in the [functions API Reference](/docs/app/api-reference/functions), the pages are sorted alphabetically because it makes it easier for developers to find a specific function:
03-functions
├── cookies.mdx
├── draft-mode.mdx
├── fetch.mdx
└── ...
But, in the [routing section](/docs/app/building-your-application/routing), the files are prefixed with a two-digit number, sorted in the order developers should learn these concepts:
02-routing
├── 01-defining-routes.mdx
├── 02-pages-and-layouts.mdx
├── 03-linking-and-navigating.mdx
└── ...
To quickly find a page, you can use `⌘ + P` (Mac) or `Ctrl + P` (Windows) to open the search bar on VSCode. Then, type the slug of the page you're looking for. E.g. `defining-routes`
> **Why not use a manifest?**
>
> We considered using a manifest file (another popular way to generate the docs navigation), but we found that a manifest would quickly get out of sync with the files. File-system routing forces us to think about the structure of the docs and feels more native to Next.js.
[Metadata](#metadata)
---------------------
Each page has a metadata block at the top of the file separated by three dashes.
### [Required Fields](#required-fields)
The following fields are **required**:
Field
Description
`title`
The page's `<h1>` title, used for SEO and OG Images.
`description`
The page's description, used in the `<meta name="description">` tag for SEO.
required-fields.mdx
---
title: Page Title
description: Page Description
---
It's good practice to limit the page title to 2-3 words (e.g. Optimizing Images) and the description to 1-2 sentences (e.g. Learn how to optimize images in Next.js).
### [Optional Fields](#optional-fields)
The following fields are **optional**:
Field
Description
`nav_title`
Overrides the page's title in the navigation. This is useful when the page's title is too long to fit. If not provided, the `title` field is used.
`source`
Pulls content into a shared page. See [Shared Pages](#shared-pages).
`related`
A list of related pages at the bottom of the document. These will automatically be turned into cards. See [Related Links](#related-links).
optional-fields.mdx
---
nav_title: Nav Item Title
source: app/building-your-application/optimizing/images
related:
description: See the image component API reference.
links:
- app/api-reference/components/image
---
[`App` and `Pages` Docs](#app-and-pages-docs)
---------------------------------------------
Since most of the features in the **App Router** and **Pages Router** are completely different, their docs for each are kept in separate sections (`02-app` and `03-pages`). However, there are a few features that are shared between them.
### [Shared Pages](#shared-pages)
To avoid content duplication and risk the content becoming out of sync, we use the `source` field to pull content from one page into another. For example, the `<Link>` component behaves _mostly_ the same in **App** and **Pages**. Instead of duplicating the content, we can pull the content from `app/.../link.mdx` into `pages/.../link.mdx`:
app/.../link.mdx
---
title: <Link>
description: API reference for the <Link> component.
---
This API reference will help you understand how to use the props
and configuration options available for the Link Component.
pages/.../link.mdx
---
title: <Link>
description: API reference for the <Link> component.
source: app/api-reference/components/link
---
{/* DO NOT EDIT THIS PAGE. */}
{/* The content of this page is pulled from the source above. */}
We can therefore edit the content in one place and have it reflected in both sections.
### [Shared Content](#shared-content)
In shared pages, sometimes there might be content that is **App Router** or **Pages Router** specific. For example, the `<Link>` component has a `shallow` prop that is only available in **Pages** but not in **App**.
To make sure the content only shows in the correct router, we can wrap content blocks in an `<AppOnly>` or `<PagesOnly>` components:
app/.../link.mdx
This content is shared between App and Pages.
<PagesOnly>
This content will only be shown on the Pages docs.
</PagesOnly>
This content is shared between App and Pages.
You'll likely use these components for examples and code blocks.
[Code Blocks](#code-blocks)
---------------------------
Code blocks should contain a minimum working example that can be copied and pasted. This means that the code should be able to run without any additional configuration.
For example, if you're showing how to use the `<Link>` component, you should include the `import` statement and the `<Link>` component itself.
app/page.tsx
import Link from 'next/link'
export default function Page() {
return <Link href="/about">About</Link>
}
Always run examples locally before committing them. This will ensure that the code is up-to-date and working.
### [Language and Filename](#language-and-filename)
Code blocks should have a header that includes the language and the `filename`. Add a `filename` prop to render a special Terminal icon that helps orientate users where to input the command. For example:
code-example.mdx
```bash filename="Terminal"
npx create-next-app
```
Most examples in the docs are written in `tsx` and `jsx`, and a few in `bash`. However, you can use any supported language, here's the [full list](https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages).
When writing JavaScript code blocks, we use the following language and extension combinations.
Language
Extension
JavaScript files with JSX code
\`\`\`jsx
.js
JavaScript files without JSX
\`\`\`js
.js
TypeScript files with JSX
\`\`\`tsx
.tsx
TypeScript files without JSX
\`\`\`ts
.ts
### [TS and JS Switcher](#ts-and-js-switcher)
Add a language switcher to toggle between TypeScript and JavaScript. Code blocks should be TypeScript first with a JavaScript version to accommodate users.
Currently, we write TS and JS examples one after the other, and link them with `switcher` prop:
code-example.mdx
```tsx filename="app/page.tsx" switcher
```
```jsx filename="app/page.js" switcher
```
> **Good to know**: We plan to automatically compile TypeScript snippets to JavaScript in the future. In the meantime, you can use [transform.tools](https://transform.tools/typescript-to-javascript).
### [Line Highlighting](#line-highlighting)
Code lines can be highlighted. This is useful when you want to draw attention to a specific part of the code. You can highlight lines by passing a number to the `highlight` prop.
**Single Line:** `highlight={1}`
app/page.tsx
import Link from 'next/link'
export default function Page() {
return <Link href="/about">About</Link>
}
**Multiple Lines:** `highlight={1,3}`
app/page.tsx
import Link from 'next/link'
export default function Page() {
return <Link href="/about">About</Link>
}
**Range of Lines:** `highlight={1-5}`
app/page.tsx
import Link from 'next/link'
export default function Page() {
return <Link href="/about">About</Link>
}
[Icons](#icons)
---------------
The following icons are available for use in the docs:
mdx-icon.mdx
<Check size={18} />
<Cross size={18} />
**Output:**
We do not use emojis in the docs.
[Notes](#notes)
---------------
For information that is important but not critical, use notes. Notes are a good way to add information without distracting the user from the main content.
notes.mdx
> **Good to know**: This is a single line note.
> **Good to know**:
>
> - We also use this format for multi-line notes.
> - There are sometimes multiple items worth knowing or keeping in mind.
**Output:**
> **Good to know**: This is a single line note.
> **Good to know**:
>
> * We also use this format for multi-line notes.
> * There are sometimes multiple item worths knowing or keeping in mind.
[Related Links](#related-links)
-------------------------------
Related Links guide the user's learning journey by adding links to logical next steps.
* Links will be displayed in cards under the main content of the page.
* Links will be automatically generated for pages that have child pages. For example, the [Optimizing](/docs/app/building-your-application/optimizing) section has links to all of its child pages.
Create related links using the `related` field in the page's metadata.
example.mdx
---
related:
description: Learn how to quickly get started with your first application.
links:
- app/building-your-application/routing/defining-routes
- app/building-your-application/data-fetching
- app/api-reference/file-conventions/page
---
### [Nested Fields](#nested-fields)
Field
Required?
Description
`title`
Optional
The title of the card list. Defaults to **Next Steps**.
`description`
Optional
The description of the card list.
`links`
Required
A list of links to other doc pages. Each list item should be a relative URL path (without a leading slash) e.g. `app/api-reference/file-conventions/page`
[Diagrams](#diagrams)
---------------------
Diagrams are a great way to explain complex concepts. We use [Figma](https://www.figma.com/) to create diagrams, following Vercel's design guide.
The diagrams currently live in the `/public` folder in our private Next.js site. If you'd like to update or add a diagram, please open a [GitHub issue](https://github.com/vercel/next.js/issues/new?assignees=&labels=template%3A+documentation&projects=&template=4.docs_request.yml&title=Docs%3A+) with your ideas.
[Custom Components and HTML](#custom-components-and-html)
---------------------------------------------------------
These are the React Components available for the docs: `<Image />` (next/image), `<PagesOnly />`, `<AppOnly />`, `<Cross />`, and `<Check />`. We do not allow raw HTML in the docs besides the `<details>` tag.
If you have ideas for new components, please open a [GitHub issue](https://github.com/vercel/next.js/issues/new/choose).
[Style Guide](#style-guide)
---------------------------
This section contains guidelines for writing docs for those who are new to technical writing.
### [Page Templates](#page-templates)
While we don't have a strict template for pages, there are page sections you'll see repeated across the docs:
* **Overview:** The first paragraph of a page should tell the user what the feature is and what it's used for. Followed by a minimum working example or its API reference.
* **Convention:** If the feature has a convention, it should be explained here.
* **Examples**: Show how the feature can be used with different use cases.
* **API Tables**: API Pages should have an overview table at the of the page with jump-to-section links (when possible).
* **Next Steps (Related Links)**: Add links to related pages to guide the user's learning journey.
Feel free to add these sections as needed.
### [Page Types](#page-types)
Docs pages are also split into two categories: Conceptual and Reference.
* **Conceptual** pages are used to explain a concept or feature. They are usually longer and contain more information than reference pages. In the Next.js docs, conceptual pages are found in the **Building Your Application** section.
* **Reference** pages are used to explain a specific API. They are usually shorter and more focused. In the Next.js docs, reference pages are found in the **API Reference** section.
> **Good to know**: Depending on the page you're contributing to, you may need to follow a different voice and style. For example, conceptual pages are more instructional and use the word _you_ to address the user. Reference pages are more technical, they use more imperative words like "create, update, accept" and tend to omit the word _you_.
### [Voice](#voice)
Here are some guidelines to maintain a consistent style and voice across the docs:
* Write clear, concise sentences. Avoid tangents.
* If you find yourself using a lot of commas, consider breaking the sentence into multiple sentences or use a list.
* Swap out complex words for simpler ones. For example, _use_ instead of _utilize_.
* Be mindful with the word _this_. It can be ambiguous and confusing, don't be afraid to repeat the subject of the sentence if unclear.
* For example, _Next.js uses React_ instead of _Next.js uses this_.
* Use an active voice instead of passive. An active sentence is easier to read.
* For example, _Next.js uses React_ instead of _React is used by Next.js_. If you find yourself using words like _was_ and _by_ you may be using a passive voice.
* Avoid using words like _easy_, _quick_, _simple_, _just_, etc. This is subjective and can be discouraging to users.
* Avoid negative words like _don't_, _can't_, _won't_, etc. This can be discouraging to readers.
* For example, _"You can use the `Link` component to create links between pages"_ instead of _"Don't use the `<a>` tag to create links between pages"_.
* Write in second person (you/your). This is more personal and engaging.
* Use gender-neutral language. Use _developers_, _users_, or _readers_, when referring to the audience.
* If adding code examples, ensure they are properly formatted and working.
While these guidelines are not exhaustive, they should help you get started. If you'd like to dive deeper into technical writing, check out the [Google Technical Writing Course](https://developers.google.com/tech-writing/overview).
* * *
Thank you for contributing to the docs and being part of the Next.js community!
[Previous
Community
](/docs/community)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"a7f5271cca733ebf283a4f5c3e2814c7\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/learn/dashboard-app | Learn Next.js
=============
Welcome to the Next.js App Router course! In this free interactive course, you'll learn the main features of Next.js by building a full-stack web application.
[What we'll be building](#what-well-be-building)
------------------------------------------------
![Screenshots of the dashboard project showing desktop and mobile versions.](/_next/image?url=%2Flearn%2Flight%2Fdashboard.png&w=3840&q=75)![Screenshots of the dashboard project showing desktop and mobile versions.](/_next/image?url=%2Flearn%2Fdark%2Fdashboard.png&w=3840&q=75)
For this course, we'll be building a simplified version of the financial dashboard that has:
* A public home page.
* A login page.
* Dashboard pages that are protected by authentication.
* The ability for users to add, edit, and delete invoices.
The dashboard will also have an accompanying database, which you'll set up in [a later chapter](/learn/dashboard-app/setting-up-your-database).
By the end of the course, you'll have the essential skills needed to start building full-stack Next.js applications.
[Overview](#overview)
---------------------
Here's an overview of features you'll learn about in this course:
* **Styling**: The different ways to style your application in Next.js.
* **Optimizations**: How to optimize images, links, and fonts.
* **Routing**: How to create nested layouts and pages using file-system routing.
* **Data Fetching**: How to set up a database on Vercel, and best practices for fetching and streaming.
* **Search and Pagination**: How to implement search and pagination using URL Search Params.
* **Mutating Data:** How to mutate data using React Server Actions, and revalidate the Next.js cache.
* **Error Handling:** How to handle general and `404` not found errors.
* **Form Validation and Accessibility:** How to do server-side form validation and tips for improving accessibility.
* **Authentication**: How to add authentication to your application using [`NextAuth.js`](https://next-auth.js.org/) and Middleware.
* **Metadata**: How to add metadata and prepare your application for social sharing.
[Prerequisite knowledge](#prerequisite-knowledge)
-------------------------------------------------
This course assumes you have a basic understanding of React and JavaScript. If you're new to React, we recommend going through our [React Foundations](/learn/react-foundations) course first to learn the fundamentals of React, such as components, props, state, and hooks, and newer features like Server Components and Suspense.
[System requirements](#system-requirements)
-------------------------------------------
Before you start this course, make sure your system meets the following requirements:
* Node.js 18.17.0 or later installed. [Download here](https://nodejs.org/en).
* Operating systems: macOS, Windows (including WSL), or Linux.
In addition, you'll also need a [GitHub Account](https://github.com/join/) and a [Vercel Account](https://vercel.com/signup).
[Join the conversation](#join-the-conversation)
-----------------------------------------------
If you have questions about this course or would like to provide feedback, you can ask our community on [Discord](https://discord.com/invite/Q3AsD4efFC) or [GitHub](https://github.com/vercel/next-learn).
Ready to get started?
---------------------
Now that you've been introduced to the course, let's dive in.
Next Up
1: Getting Started
Learn how to create a Next.js application and run your local development server.
[Start Chapter 1](/learn/dashboard-app/getting-started)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"7c34f8cf9cb1886ef1756420d5d0b4c1\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/optimizePackageImports | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [
optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Disabling compression](#disabling-compression)
* [Changing the compression algorithm](#changing-the-compression-algorithm)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/optimizePackageImports.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)optimizePackageImports
optimizePackageImports
======================
By default, Next.js uses `gzip` to compress rendered content and static files when using `next start` or a custom server. This is an optimization for applications that do not have compression configured. If compression is _already_ configured in your application via a custom server, Next.js will not add compression.
> **Good to know:**
>
> * When hosting your application on [Vercel](https://vercel.com/docs/edge-network/compression), compression uses `brotli` first, then `gzip`.
> * You can check if compression is enabled and which algorithm is used by looking at the [`Accept-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) (browser accepted options) and [`Content-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding) (currently used) headers in the response.
[Disabling compression](#disabling-compression)
-----------------------------------------------
To disable **compression**, set the `compress` config option to `false`:
next.config.js
module.exports = {
compress: false,
}
We do not recommend disabling compression unless you have compression configured on your server, as compression reduces bandwidth usage and improves the performance of your application.
[Changing the compression algorithm](#changing-the-compression-algorithm)
-------------------------------------------------------------------------
To change your compression algorithm, you will need to configure your custom server and set the `compress` option to `false` in your `next.config.js` file.
For example, you're using [nginx](https://www.nginx.com/) and want to switch to `brotli`, set the `compress` option to `false` to allow nginx to handle compression.
> **Good to know:**
>
> * For Next.js applications on Vercel, compression is handled by the Vercel's Edge Network and not Next.js. See the [Vercel documentation](https://vercel.com/docs/edge-network/compression) for more information.
[Previous
onDemandEntries
](/docs/pages/api-reference/next-config-js/onDemandEntries)
[Next
output
](/docs/pages/api-reference/next-config-js/output)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"653ce8e060307d882f5adf207fc552c5\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/onDemandEntries | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [
onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/onDemandEntries.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)onDemandEntries
onDemandEntries
===============
Next.js exposes some options that give you some control over how the server will dispose or keep in memory built pages in development.
To change the defaults, open `next.config.js` and add the `onDemandEntries` config:
next.config.js
module.exports = {
onDemandEntries: {
// period (in ms) where the server will keep pages in the buffer
maxInactiveAge: 25 * 1000,
// number of pages that should be kept simultaneously without being disposed
pagesBufferLength: 2,
},
}
[Previous
instrumentationHook
](/docs/pages/api-reference/next-config-js/instrumentationHook)
[Next
optimizePackageImports
](/docs/pages/api-reference/next-config-js/optimizePackageImports)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"0792f19cb67d9bef8bf4625fee72afd2\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/poweredByHeader | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [
poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/poweredByHeader.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)poweredByHeader
poweredByHeader
===============
By default Next.js will add the `x-powered-by` header. To opt-out of it, open `next.config.js` and disable the `poweredByHeader` config:
next.config.js
module.exports = {
poweredByHeader: false,
}
[Previous
pageExtensions
](/docs/pages/api-reference/next-config-js/pageExtensions)
[Next
productionBrowserSourceMaps
](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"ce75b56372a7aa6a5d04cd8b3c737732\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [
productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/productionBrowserSourceMaps.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)productionBrowserSourceMaps
productionBrowserSourceMaps
===========================
Source Maps are enabled by default during development. During production builds, they are disabled to prevent you leaking your source on the client, unless you specifically opt-in with the configuration flag.
Next.js provides a configuration flag you can use to enable browser source map generation during the production build:
next.config.js
module.exports = {
productionBrowserSourceMaps: true,
}
When the `productionBrowserSourceMaps` option is enabled, the source maps will be output in the same directory as the JavaScript files. Next.js will automatically serve these files when requested.
* Adding source maps can increase `next build` time
* Increases memory usage during `next build`
[Previous
poweredByHeader
](/docs/pages/api-reference/next-config-js/poweredByHeader)
[Next
reactStrictMode
](/docs/pages/api-reference/next-config-js/reactStrictMode)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"90d53c45e68e8a4805a5fe0d38a1aae8\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/output | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [
output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [How it Works](#how-it-works)
* [Automatically Copying Traced Files](#automatically-copying-traced-files)
* [Caveats](#caveats)
* [Experimental turbotrace](#experimental-turbotrace)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/output.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)output
output
======
During a build, Next.js will automatically trace each page and its dependencies to determine all of the files that are needed for deploying a production version of your application.
This feature helps reduce the size of deployments drastically. Previously, when deploying with Docker you would need to have all files from your package's `dependencies` installed to run `next start`. Starting with Next.js 12, you can leverage Output File Tracing in the `.next/` directory to only include the necessary files.
Furthermore, this removes the need for the deprecated `serverless` target which can cause various issues and also creates unnecessary duplication.
[How it Works](#how-it-works)
-----------------------------
During `next build`, Next.js will use [`@vercel/nft`](https://github.com/vercel/nft) to statically analyze `import`, `require`, and `fs` usage to determine all files that a page might load.
Next.js' production server is also traced for its needed files and output at `.next/next-server.js.nft.json` which can be leveraged in production.
To leverage the `.nft.json` files emitted to the `.next` output directory, you can read the list of files in each trace that are relative to the `.nft.json` file and then copy them to your deployment location.
[Automatically Copying Traced Files](#automatically-copying-traced-files)
-------------------------------------------------------------------------
Next.js can automatically create a `standalone` folder that copies only the necessary files for a production deployment including select files in `node_modules`.
To leverage this automatic copying you can enable it in your `next.config.js`:
next.config.js
module.exports = {
output: 'standalone',
}
This will create a folder at `.next/standalone` which can then be deployed on its own without installing `node_modules`.
Additionally, a minimal `server.js` file is also output which can be used instead of `next start`. This minimal server does not copy the `public` or `.next/static` folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the `standalone/public` and `standalone/.next/static` folders manually, after which `server.js` file will serve these automatically.
> **Good to know**:
>
> * `next.config.js` is read during `next build` and serialized into the `server.js` output file. If the legacy [`serverRuntimeConfig` or `publicRuntimeConfig` options](/docs/pages/api-reference/next-config-js/runtime-configuration) are being used, the values will be specific to values at build time.
> * If your project needs to listen to a specific port or hostname, you can define `PORT` or `HOSTNAME` environment variables before running `server.js`. For example, run `PORT=8080 HOSTNAME=0.0.0.0 node server.js` to start the server on `http://0.0.0.0:8080`.
> * If your project uses [Image Optimization](/docs/pages/building-your-application/optimizing/images) with the default `loader`, you must install `sharp` as a dependency:
Terminal
npm i sharp
Terminal
yarn add sharp
Terminal
pnpm add sharp
Terminal
bun add sharp
[Caveats](#caveats)
-------------------
* While tracing in monorepo setups, the project directory is used for tracing by default. For `next build packages/web-app`, `packages/web-app` would be the tracing root and any files outside of that folder will not be included. To include files outside of this folder you can set `experimental.outputFileTracingRoot` in your `next.config.js`.
packages/web-app/next.config.js
module.exports = {
experimental: {
// this includes files from the monorepo base two directories up
outputFileTracingRoot: path.join(__dirname, '../../'),
},
}
* There are some cases in which Next.js might fail to include required files, or might incorrectly include unused files. In those cases, you can leverage `experimental.outputFileTracingExcludes` and `experimental.outputFileTracingIncludes` respectively in `next.config.js`. Each config accepts an object with [minimatch globs](https://www.npmjs.com/package/minimatch) for the key to match specific pages and a value of an array with globs relative to the project's root to either include or exclude in the trace.
next.config.js
module.exports = {
experimental: {
outputFileTracingExcludes: {
'/api/hello': ['./un-necessary-folder/**/*'],
},
outputFileTracingIncludes: {
'/api/another': ['./necessary-folder/**/*'],
},
},
}
* Currently, Next.js does not do anything with the emitted `.nft.json` files. The files must be read by your deployment platform, for example [Vercel](https://vercel.com), to create a minimal deployment. In a future release, a new command is planned to utilize these `.nft.json` files.
[Experimental `turbotrace`](#experimental-turbotrace)
-----------------------------------------------------
Tracing dependencies can be slow because it requires very complex computations and analysis. We created `turbotrace` in Rust as a faster and smarter alternative to the JavaScript implementation.
To enable it, you can add the following configuration to your `next.config.js`:
next.config.js
module.exports = {
experimental: {
turbotrace: {
// control the log level of the turbotrace, default is `error`
logLevel?:
| 'bug'
| 'fatal'
| 'error'
| 'warning'
| 'hint'
| 'note'
| 'suggestions'
| 'info',
// control if the log of turbotrace should contain the details of the analysis, default is `false`
logDetail?: boolean
// show all log messages without limit
// turbotrace only show 1 log message for each categories by default
logAll?: boolean
// control the context directory of the turbotrace
// files outside of the context directory will not be traced
// set the `experimental.outputFileTracingRoot` has the same effect
// if the `experimental.outputFileTracingRoot` and this option are both set, the `experimental.turbotrace.contextDirectory` will be used
contextDirectory?: string
// if there is `process.cwd()` expression in your code, you can set this option to tell `turbotrace` the value of `process.cwd()` while tracing.
// for example the require(process.cwd() + '/package.json') will be traced as require('/path/to/cwd/package.json')
processCwd?: string
// control the maximum memory usage of the `turbotrace`, in `MB`, default is `6000`.
memoryLimit?: number
},
},
}
[Previous
optimizePackageImports
](/docs/pages/api-reference/next-config-js/optimizePackageImports)
[Next
pageExtensions
](/docs/pages/api-reference/next-config-js/pageExtensions)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"146e847c32b89dec991e2bf2cfe76353\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/app | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Frequently Asked Questions](#frequently-asked-questions)
* [How can I access the request object in a layout?](#how-can-i-access-the-request-object-in-a-layout)
* [How can I access the URL on a page?](#how-can-i-access-the-url-on-a-page)
* [How can I redirect from a Server Component?](#how-can-i-redirect-from-a-server-component)
* [How can I handle authentication with the App Router?](#how-can-i-handle-authentication-with-the-app-router)
* [How can I set cookies?](#how-can-i-set-cookies)
* [How can I build multi-tenant apps?](#how-can-i-build-multi-tenant-apps)
* [How can I invalidate the App Router cache?](#how-can-i-invalidate-the-app-router-cache)
* [Are there any comprehensive, open-source applications built on the App Router?](#are-there-any-comprehensive-open-source-applications-built-on-the-app-router)
* [Learn More](#learn-more)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/02-app/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
App Router
==========
The Next.js App Router introduces a new model for building applications using React's latest features such as [Server Components](/docs/app/building-your-application/rendering/server-components), [Streaming with Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense), and [Server Actions](/docs/app/building-your-application/data-fetching/server-actions-and-mutations).
Get started with the App Router by [creating your first page](/docs/app/building-your-application/routing/pages-and-layouts).
[Frequently Asked Questions](#frequently-asked-questions)
---------------------------------------------------------
### [How can I access the request object in a layout?](#how-can-i-access-the-request-object-in-a-layout)
You intentionally cannot access the raw request object. However, you can access [`headers`](/docs/app/api-reference/functions/headers) and [`cookies`](/docs/app/api-reference/functions/cookies) through server-only functions. You can also [set cookies](#how-can-i-set-cookies).
[Layouts](/docs/app/building-your-application/routing/pages-and-layouts#layouts) do not rerender. They can be cached and reused to avoid unnecessary computation when navigating between pages. By restricting layouts from accessing the raw request, Next.js can prevent the execution of potentially slow or expensive user code within the layout, which could negatively impact performance.
This design also enforces consistent and predictable behavior for layouts across different pages, which simplifies development and debugging.
Depending on the UI pattern you're building, [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes) allow you to render multiple pages in the same layout, and pages have access to the route segments as well as the URL search params.
### [How can I access the URL on a page?](#how-can-i-access-the-url-on-a-page)
By default, pages are Server Components. You can access the route segments through the [`params`](/docs/app/api-reference/file-conventions/page#params-optional) prop and the URL search params through the [`searchParams`](/docs/app/api-reference/file-conventions/page#searchparams-optional) prop for a given page.
If you are using Client Components, you can use [`usePathname`](/docs/app/api-reference/functions/use-pathname), [`useSelectedLayoutSegment`](/docs/app/api-reference/functions/use-selected-layout-segment), and [`useSelectedLayoutSegments`](/docs/app/api-reference/functions/use-selected-layout-segments) for more complex routes.
Further, depending on the UI pattern you're building, [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes) allow you to render multiple pages in the same layout, and pages have access to the route segments as well as the URL search params.
### [How can I redirect from a Server Component?](#how-can-i-redirect-from-a-server-component)
You can use [`redirect`](/docs/app/api-reference/functions/redirect) to redirect from a page to a relative or absolute URL. [`redirect`](/docs/app/api-reference/functions/redirect) is a temporary (307) redirect, while [`permanentRedirect`](/docs/app/api-reference/functions/permanentRedirect) is a permanent (308) redirect. When these functions are used while streaming UI, they will insert a meta tag to emit the redirect on the client side.
### [How can I handle authentication with the App Router?](#how-can-i-handle-authentication-with-the-app-router)
Here are some common authentication solutions that support the App Router:
* [NextAuth.js](https://next-auth.js.org/configuration/nextjs#in-app-router)
* [Clerk](https://clerk.com/docs/quickstarts/nextjs)
* [Lucia](https://lucia-auth.com/getting-started/nextjs-app)
* [Auth0](https://github.com/auth0/nextjs-auth0#app-router)
* [Stytch](https://stytch.com/docs/example-apps/frontend/nextjs)
* [Kinde](https://kinde.com/docs/developer-tools/nextjs-sdk/)
* Or manually handling sessions or JWTs
### [How can I set cookies?](#how-can-i-set-cookies)
You can set cookies in [Server Actions](/docs/app/building-your-application/data-fetching/server-actions-and-mutations#cookies) or [Route Handlers](/docs/app/building-your-application/routing/route-handlers) using the [`cookies`](/docs/app/api-reference/functions/cookies) function.
Since HTTP does not allow setting cookies after streaming starts, you cannot set cookies from a page or layout directly. You can also set cookies from [Middleware](/docs/app/building-your-application/routing/middleware#using-cookies).
### [How can I build multi-tenant apps?](#how-can-i-build-multi-tenant-apps)
If you are looking to build a single Next.js application that serves multiple tenants, we have [built an example](https://vercel.com/templates/next.js/platforms-starter-kit) showing our recommended architecture.
### [How can I invalidate the App Router cache?](#how-can-i-invalidate-the-app-router-cache)
There are multiple layers of caching in Next.js, and thus, multiple ways to invalidate different parts of the cache. [Learn more about caching](/docs/app/building-your-application/caching).
### [Are there any comprehensive, open-source applications built on the App Router?](#are-there-any-comprehensive-open-source-applications-built-on-the-app-router)
Yes. You can view [Next.js Commerce](https://vercel.com/templates/next.js/nextjs-commerce) or the [Platforms Starter Kit](https://vercel.com/templates/next.js/platforms-starter-kit) for two larger examples of using the App Router that are open-source.
[Learn More](#learn-more)
-------------------------
* [Routing Fundamentals](/docs/app/building-your-application/routing)
* [Data Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Forms and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Caching](/docs/app/building-your-application/caching)
* [Rendering Fundamentals](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
[
### Building Your Application
Learn how to use Next.js features to build your application.
](/docs/app/building-your-application)[
### API Reference
Next.js API Reference for the App Router.
](/docs/app/api-reference)
[Previous
Project Structure
](/docs/getting-started/project-structure)
[Next
Building Your Application
](/docs/app/building-your-application)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"1a15897e0fceb274fd8b621672ffd4e1\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/index.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
Pages Router
============
Before Next.js 13, the Pages Router was the main way to create routes in Next.js. It used an intuitive file-system router to map each file to a route. The Pages Router is still supported in newer versions of Next.js, but we recommend migrating to the new [App Router](/docs/app) to leverage React's latest features.
Use this section of the documentation for existing applications that use the Pages Router.
[
### Building Your Application
Learn how to use Next.js features to build your application.
](/docs/pages/building-your-application)[
### API Reference
Next.js API Reference for the Pages Router.
](/docs/pages/api-reference)
[Previous
Project Structure
](/docs/getting-started/project-structure)
[Next
Building Your Application
](/docs/pages/building-your-application)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"cca616663440c53fd1e4cd2a77c55593\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/telemetry | Telemetry
=========
Next.js collects **completely anonymous** telemetry data about general usage. Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information.
[Why is telemetry collected?](#why-is-telemetry-collected)
----------------------------------------------------------
Next.js has grown considerably since its release, becoming the de-facto React Framework for developers. Prior to telemetry collection, making decisions about how to improve Next.js was a very manual process.
For example, Vercel [dogfoods](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) many large React applications (including the Next.js website). Additionally, we actively engage with the community to gather feedback.
However, this approach only allows us to collect feedback from a subset of users. This subset may have different needs and use cases than you. Telemetry allows us to accurately gauge Next.js feature usage, pain points, and customization across all users.
This data will let us better tailor Next.js to the masses, ensuring its continued growth, relevance, and best-in-class developer experience. Furthermore, this will allow us to verify if improvements made to the framework are improving the baseline of all applications.
[What is being collected?](#what-is-being-collected)
----------------------------------------------------
We track general usage information, such as Next.js plugins and build performance. Specifically, we track the following anonymously:
* Command invoked (`next build`, `next dev`, or `next export`)
* Version of Next.js
* General machine information (e.g. number of CPUs, macOS/Windows/Linux, whether or not the command was run within CI)
* What Next.js plugins are present in your project
* Duration of `next build` and size of application (total number of pages)
> **Note**: This list is regularly audited to ensure its accuracy.
You can view exactly what is being collected by setting the following environment variable: `NEXT_TELEMETRY_DEBUG=1`.
When this environment variable is set, data will **not be sent to us**. The data will only be printed out to the [_stderr_ stream](https://en.wikipedia.org/wiki/Standard_streams), prefixed with `[telemetry]`.
An example telemetry event looks like this:
{
"eventName": "NEXT_VERSION",
"payload": {
"version": "9.0.5-canary.2",
"isDevelopment": false
}
}
[What about sensitive data (e.g. secrets)?](#what-about-sensitive-data-eg-secrets)
----------------------------------------------------------------------------------
We **do not** collect any metrics which may contain sensitive data.
This includes, but is not limited to: environment variables, file paths, contents of files, logs, or serialized JavaScript errors.
We take privacy and our security very seriously. Next.js telemetry falls under the [security disclosure policy](https://vercel.com/security).
[Will this data be shared?](#will-this-data-be-shared)
------------------------------------------------------
The data we collect is completely anonymous, not traceable to the source, and only meaningful in aggregate form.
**No data we collect is personally identifiable.**
[How do I opt-out?](#how-do-i-opt-out)
--------------------------------------
You may opt out-by running `next telemetry disable` in the root of your project directory:
npx next telemetry disable
yarn next telemetry disable
pnpm exec next telemetry disable
bun next telemetry disable
You may check the status of telemetry collection at any time by running `next telemetry status` in the root of your project directory:
npx next telemetry status
yarn next telemetry status
pnpm exec next telemetry status
bun next telemetry status
You may re-enable telemetry if you'd like to re-join the program by running the following in the root of your project directory:
npx next telemetry enable
yarn next telemetry enable
pnpm exec next telemetry enable
bun next telemetry enable
You may also opt-out by setting an environment variable: `NEXT_TELEMETRY_DISABLED=1`. |
{
"contentLength": null,
"etag": "W/\"f7a5c94ba3f18906e736c00c8e5d0c2f\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [
rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Rewrite parameters](#rewrite-parameters)
* [Path Matching](#path-matching)
* [Wildcard Path Matching](#wildcard-path-matching)
* [Regex Path Matching](#regex-path-matching)
* [Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
* [Rewriting to an external URL](#rewriting-to-an-external-url)
* [Incremental adoption of Next.js](#incremental-adoption-of-nextjs)
* [Rewrites with basePath support](#rewrites-with-basepath-support)
* [Rewrites with i18n support](#rewrites-with-i18n-support)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/rewrites.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)rewrites
rewrites
========
Rewrites allow you to map an incoming request path to a different destination path.
Rewrites act as a URL proxy and mask the destination path, making it appear the user hasn't changed their location on the site. In contrast, [redirects](/docs/pages/api-reference/next-config-js/redirects) will reroute to a new page and show the URL changes.
To use rewrites you can use the `rewrites` key in `next.config.js`:
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/about',
destination: '/',
},
]
},
}
Rewrites are applied to client-side routing, a `<Link href="/about">` will have the rewrite applied in the above example.
`rewrites` is an async function that expects to return either an array or an object of arrays (see below) holding objects with `source` and `destination` properties:
* `source`: `String` - is the incoming request path pattern.
* `destination`: `String` is the path you want to route to.
* `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only.
* `locale`: `false` or `undefined` - whether the locale should not be included when matching.
* `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
* `missing` is an array of [missing objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
When the `rewrites` function returns an array, rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes. When the `rewrites` function returns an object of arrays with a specific shape, this behavior can be changed and more finely controlled, as of `v10.1` of Next.js:
next.config.js
module.exports = {
async rewrites() {
return {
beforeFiles: [
// These rewrites are checked after headers/redirects
// and before all files including _next/public files which
// allows overriding page files
{
source: '/some-page',
destination: '/somewhere-else',
has: [{ type: 'query', key: 'overrideMe' }],
},
],
afterFiles: [
// These rewrites are checked after pages/public files
// are checked but before dynamic routes
{
source: '/non-existent',
destination: '/somewhere-else',
},
],
fallback: [
// These rewrites are checked after both pages/public files
// and dynamic routes are checked
{
source: '/:path*',
destination: `https://my-old-site.com/:path*`,
},
],
}
},
}
> **Good to know**: rewrites in `beforeFiles` do not check the filesystem/dynamic routes immediately after matching a source, they continue until all `beforeFiles` have been checked.
The order Next.js routes are checked is:
1. [headers](/docs/pages/api-reference/next-config-js/headers) are checked/applied
2. [redirects](/docs/pages/api-reference/next-config-js/redirects) are checked/applied
3. `beforeFiles` rewrites are checked/applied
4. static files from the [public directory](/docs/pages/building-your-application/optimizing/static-assets), `_next/static` files, and non-dynamic pages are checked/served
5. `afterFiles` rewrites are checked/applied, if one of these rewrites is matched we check dynamic routes/static files after each match
6. `fallback` rewrites are checked/applied, these are applied before rendering the 404 page and after dynamic routes/all static assets have been checked. If you use [fallback: true/'blocking'](/docs/pages/api-reference/functions/get-static-paths#fallback-true) in `getStaticPaths`, the fallback `rewrites` defined in your `next.config.js` will _not_ be run.
[Rewrite parameters](#rewrite-parameters)
-----------------------------------------
When using parameters in a rewrite the parameters will be passed in the query by default when none of the parameters are used in the `destination`.
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/old-about/:path*',
destination: '/about', // The :path parameter isn't used here so will be automatically passed in the query
},
]
},
}
If a parameter is used in the destination none of the parameters will be automatically passed in the query.
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/docs/:path*',
destination: '/:path*', // The :path parameter is used here so will not be automatically passed in the query
},
]
},
}
You can still pass the parameters manually in the query if one is already used in the destination by specifying the query in the `destination`.
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/:first/:second',
destination: '/:first?second=:second',
// Since the :first parameter is used in the destination the :second parameter
// will not automatically be added in the query although we can manually add it
// as shown above
},
]
},
}
> **Good to know**: Static pages from [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization) or [prerendering](/docs/pages/building-your-application/data-fetching/get-static-props) params from rewrites will be parsed on the client after hydration and provided in the query.
[Path Matching](#path-matching)
-------------------------------
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/blog/:slug',
destination: '/news/:slug', // Matched parameters can be used in the destination
},
]
},
}
### [Wildcard Path Matching](#wildcard-path-matching)
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/blog/:slug*',
destination: '/news/:slug*', // Matched parameters can be used in the destination
},
]
},
}
### [Regex Path Matching](#regex-path-matching)
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/old-blog/:post(\\d{1,})',
destination: '/blog/:post', // Matched parameters can be used in the destination
},
]
},
}
The following characters `(`, `)`, `{`, `}`, `[`, `]`, `|`, `\`, `^`, `.`, `:`, `*`, `+`, `-`, `?`, `$` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
next.config.js
module.exports = {
async rewrites() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
destination: '/en-us/:slug',
},
]
},
}
[Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
-----------------------------------------------------------------------
To only match a rewrite when header, cookie, or query values also match the `has` field or don't match the `missing` field can be used. Both the `source` and all `has` items must match and all `missing` items must not match for the rewrite to be applied.
`has` and `missing` items can have the following fields:
* `type`: `String` - must be either `header`, `cookie`, `host`, or `query`.
* `key`: `String` - the key from the selected type to match against.
* `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.
next.config.js
module.exports = {
async rewrites() {
return [
// if the header `x-rewrite-me` is present,
// this rewrite will be applied
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-rewrite-me',
},
],
destination: '/another-page',
},
// if the header `x-rewrite-me` is not present,
// this rewrite will be applied
{
source: '/:path*',
missing: [
{
type: 'header',
key: 'x-rewrite-me',
},
],
destination: '/another-page',
},
// if the source, query, and cookie are matched,
// this rewrite will be applied
{
source: '/specific/:path*',
has: [
{
type: 'query',
key: 'page',
// the page value will not be available in the
// destination since value is provided and doesn't
// use a named capture group e.g. (?<page>home)
value: 'home',
},
{
type: 'cookie',
key: 'authorized',
value: 'true',
},
],
destination: '/:path*/home',
},
// if the header `x-authorized` is present and
// contains a matching value, this rewrite will be applied
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-authorized',
value: '(?<authorized>yes|true)',
},
],
destination: '/home?authorized=:authorized',
},
// if the host is `example.com`,
// this rewrite will be applied
{
source: '/:path*',
has: [
{
type: 'host',
value: 'example.com',
},
],
destination: '/another-page',
},
]
},
}
[Rewriting to an external URL](#rewriting-to-an-external-url)
-------------------------------------------------------------
Examples
* [Incremental adoption of Next.js](https://github.com/vercel/next.js/tree/canary/examples/custom-routes-proxying)
* [Using Multiple Zones](https://github.com/vercel/next.js/tree/canary/examples/with-zones)
Rewrites allow you to rewrite to an external url. This is especially useful for incrementally adopting Next.js. The following is an example rewrite for redirecting the `/blog` route of your main app to an external site.
next.config.js
module.exports = {
async rewrites() {
return [
{
source: '/blog',
destination: 'https://example.com/blog',
},
{
source: '/blog/:slug',
destination: 'https://example.com/blog/:slug', // Matched parameters can be used in the destination
},
]
},
}
If you're using `trailingSlash: true`, you also need to insert a trailing slash in the `source` parameter. If the destination server is also expecting a trailing slash it should be included in the `destination` parameter as well.
next.config.js
module.exports = {
trailingSlash: true,
async rewrites() {
return [
{
source: '/blog/',
destination: 'https://example.com/blog/',
},
{
source: '/blog/:path*/',
destination: 'https://example.com/blog/:path*/',
},
]
},
}
### [Incremental adoption of Next.js](#incremental-adoption-of-nextjs)
You can also have Next.js fall back to proxying to an existing website after checking all Next.js routes.
This way you don't have to change the rewrites configuration when migrating more pages to Next.js
next.config.js
module.exports = {
async rewrites() {
return {
fallback: [
{
source: '/:path*',
destination: `https://custom-routes-proxying-endpoint.vercel.app/:path*`,
},
],
}
},
}
### [Rewrites with basePath support](#rewrites-with-basepath-support)
When leveraging [`basePath` support](/docs/app/api-reference/next-config-js/basePath) with rewrites each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the rewrite:
next.config.js
module.exports = {
basePath: '/docs',
async rewrites() {
return [
{
source: '/with-basePath', // automatically becomes /docs/with-basePath
destination: '/another', // automatically becomes /docs/another
},
{
// does not add /docs to /without-basePath since basePath: false is set
// Note: this can not be used for internal rewrites e.g. `destination: '/another'`
source: '/without-basePath',
destination: 'https://example.com',
basePath: false,
},
]
},
}
### [Rewrites with i18n support](#rewrites-with-i18n-support)
When leveraging [`i18n` support](/docs/pages/building-your-application/routing/internationalization) with rewrites each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the rewrite. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.
next.config.js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},
async rewrites() {
return [
{
source: '/with-locale', // automatically handles all locales
destination: '/another', // automatically passes the locale on
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
destination: '/nl/another',
locale: false,
},
{
// this matches '/' since `en` is the defaultLocale
source: '/en',
destination: '/en/another',
locale: false,
},
{
// it's possible to match all locales even when locale: false is set
source: '/:locale/api-alias/:path*',
destination: '/api/:path*',
locale: false,
},
{
// this gets converted to /(en|fr|de)/(.*) so will not match the top-level
// `/` or `/fr` routes like /:path* would
source: '/(.*)',
destination: '/another',
},
]
},
}
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.3.0`
`missing` added.
`v10.2.0`
`has` added.
`v9.5.0`
Headers added.
[Previous
redirects
](/docs/pages/api-reference/next-config-js/redirects)
[Next
Runtime Config
](/docs/pages/api-reference/next-config-js/runtime-configuration)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"50a65f0b266b934eb99d673058285577\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/reactStrictMode | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [
reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/reactStrictMode.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)reactStrictMode
reactStrictMode
===============
> **Good to know**: Since Next.js 13.4, Strict Mode is `true` by default with `app` router, so the above configuration is only necessary for `pages`. You can still disable Strict Mode by setting `reactStrictMode: false`.
> **Suggested**: We strongly suggest you enable Strict Mode in your Next.js application to better prepare your application for the future of React.
React's [Strict Mode](https://react.dev/reference/react/StrictMode) is a development mode only feature for highlighting potential problems in an application. It helps to identify unsafe lifecycles, legacy API usage, and a number of other features.
The Next.js runtime is Strict Mode-compliant. To opt-in to Strict Mode, configure the following option in your `next.config.js`:
next.config.js
module.exports = {
reactStrictMode: true,
}
If you or your team are not ready to use Strict Mode in your entire application, that's OK! You can incrementally migrate on a page-by-page basis using `<React.StrictMode>`.
[Previous
productionBrowserSourceMaps
](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
[Next
redirects
](/docs/pages/api-reference/next-config-js/redirects)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"7121695f8eccb5b061946babd6f83f8a\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/trailingSlash | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [
trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/trailingSlash.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)trailingSlash
trailingSlash
=============
By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example `/about/` will redirect to `/about`. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes.
Open `next.config.js` and add the `trailingSlash` config:
next.config.js
module.exports = {
trailingSlash: true,
}
With this option set, urls like `/about` will redirect to `/about/`.
When used with [`output: "export"`](/docs/app/building-your-application/deploying/static-exports) configuration, the `/about` page will output `/about/index.html` (instead of the default `/about.html`).
[Version History](#version-history)
-----------------------------------
Version
Changes
`v9.5.0`
`trailingSlash` added.
[Previous
Runtime Config
](/docs/pages/api-reference/next-config-js/runtime-configuration)
[Next
transpilePackages
](/docs/pages/api-reference/next-config-js/transpilePackages)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": null,
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/conf | Watch KeynoteWatch Keynote
By registering for this event, you agree to our [Event Terms & Conditions](https://vercel.com/legal/event-terms-conditions) and [Privacy Policy](http://vercel.com/privacy) |
{
"contentLength": null,
"etag": "W/\"ddeec85c087875afdaa26a08cb70beb1\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/governance | Governance
==========
Next.js was created by the team at [Vercel](https://vercel.com?utm_source=next-site&utm_medium=governance) in 2016.
The research and development of Next.js is led by the core team working full-time at Vercel. With over 3,000 contributors from around the world, Next.js is a collaborative open-source effort to build tools for React and Web developers.
[Teams](#teams)
---------------
* **Lead:** [Tim Neutkens](https://twitter.com/timneutkens), Next.js Lead and Co-Creator
* **Core Team:** Next.js team at [Vercel](https://vercel.com?utm_source=next-site&utm_medium=governance) manages the direction of Next.js and leadership of the project, as well as [SWC](https://swc.rs/), [Webpack](https://webpack.js.org/), and [Turbopack](https://turbo.build/pack)
* **Documentation:** DevRel teams at [Vercel](https://vercel.com?utm_source=next-site&utm_medium=governance) manage documentation and learning platforms
* **Collaborators:** [React team at Meta](https://react.dev/community/team) and the [Aurora team at Google](https://developer.chrome.com/blog/introducing-aurora/)
[Roadmap and RFC Process](#roadmap-and-rfc-process)
---------------------------------------------------
Large architecture decisions and features start as a [Request for Comments (RFC)](https://github.com/vercel/next.js/discussions/categories/rfc) inside GitHub Discussions. The entire Next.js community is invited be to involved in the process and discuss the tradeoffs of proposed work.
This process is essential to ensure features are built together with the community and our collaborators. More minor changes including bug fixes and documentation improvements are still implemented through GitHub pull requests. However, for larger initiatives, we believe it's essential to follow the RFC process.
[Stability and Release Phases](#stability-and-release-phases)
-------------------------------------------------------------
Next.js follows [Semantic Versioning](https://semver.org/) and releases new versions on a regular basis.
* **Experimental:** Experimental features lack essential capabilities required to be ready for stability. The feature is considered to be under active development and is being built to transition into Beta.
* **Beta:** Beta means the feature does not yet meet our quality standards for a stable release. There is also usually a need for more information or feedback from Next.js developers to validate this feature works as expected in a variety of environments.
* **Stable:** When the features reach stability, it is considered ready for use in production. APIs marked as stable will only change in a backward-compatible way unless there is a [major release](https://semver.org/).
* **Deprecated:** A feature is in the process of being removed. Deprecated features include documentation for existing users with the next steps and information on when to expect the feature to be removed.
[Next.js Support](#nextjs-support)
----------------------------------
For individual developers looking for free support on their Next.js application, they can ask questions in [GitHub Discussions](https://github.com/vercel/next.js/discussions) or in the [Next.js Discord](https://nextjs.org/discord).
For companies looking for paid support on their Next.js application, they can [contact](https://vercel.com/contact/sales?utm_source=next-site&utm_medium=governance) the Next.js team at Vercel for more information.
[Additional Resources](#additional-resources)
---------------------------------------------
* [Logo Policy and Brand Guidelines](https://vercel.com/design/brands#next-js)
* [Reporting Security Issues](https://github.com/vercel/next.js/security/policy)
* [Code of Conduct](https://github.com/vercel/next.js/blob/canary/CODE_OF_CONDUCT.md)
* [Contributing Guidelines](https://github.com/vercel/next.js/blob/canary/contributing.md) |
{
"contentLength": null,
"etag": "W/\"453545e68ce49a7168ed8fd8ec60cd37\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/redirects | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [
redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Path Matching](#path-matching)
* [Wildcard Path Matching](#wildcard-path-matching)
* [Regex Path Matching](#regex-path-matching)
* [Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
* [Redirects with basePath support](#redirects-with-basepath-support)
* [Redirects with i18n support](#redirects-with-i18n-support)
* [Other Redirects](#other-redirects)
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/redirects.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)redirects
redirects
=========
Redirects allow you to redirect an incoming request path to a different destination path.
To use redirects you can use the `redirects` key in `next.config.js`:
next.config.js
module.exports = {
async redirects() {
return [
{
source: '/about',
destination: '/',
permanent: true,
},
]
},
}
`redirects` is an async function that expects an array to be returned holding objects with `source`, `destination`, and `permanent` properties:
* `source` is the incoming request path pattern.
* `destination` is the path you want to route to.
* `permanent` `true` or `false` - if `true` will use the 308 status code which instructs clients/search engines to cache the redirect forever, if `false` will use the 307 status code which is temporary and is not cached.
> **Why does Next.js use 307 and 308?** Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect to `GET`, regardless of the original method. For example, if the browser made a request to `POST /v1/users` which returned status code `302` with location `/v2/users`, the subsequent request might be `GET /v2/users` instead of the expected `POST /v2/users`. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes to explicitly preserve the request method used.
* `basePath`: `false` or `undefined` - if false the `basePath` won't be included when matching, can be used for external redirects only.
* `locale`: `false` or `undefined` - whether the locale should not be included when matching.
* `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
* `missing` is an array of [missing objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
Redirects are checked before the filesystem which includes pages and `/public` files.
When using the Pages Router, redirects are not applied to client-side routing (`Link`, `router.push`) unless [Middleware](/docs/app/building-your-application/routing/middleware) is present and matches the path.
When a redirect is applied, any query values provided in the request will be passed through to the redirect destination. For example, see the following redirect configuration:
{
source: '/old-blog/:path*',
destination: '/blog/:path*',
permanent: false
}
When `/old-blog/post-1?hello=world` is requested, the client will be redirected to `/blog/post-1?hello=world`.
[Path Matching](#path-matching)
-------------------------------
Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/hello-world` (no nested paths):
next.config.js
module.exports = {
async redirects() {
return [
{
source: '/old-blog/:slug',
destination: '/news/:slug', // Matched parameters can be used in the destination
permanent: true,
},
]
},
}
### [Wildcard Path Matching](#wildcard-path-matching)
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:
next.config.js
module.exports = {
async redirects() {
return [
{
source: '/blog/:slug*',
destination: '/news/:slug*', // Matched parameters can be used in the destination
permanent: true,
},
]
},
}
### [Regex Path Matching](#regex-path-matching)
To match a regex path you can wrap the regex in parentheses after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:
next.config.js
module.exports = {
async redirects() {
return [
{
source: '/post/:slug(\\d{1,})',
destination: '/news/:slug', // Matched parameters can be used in the destination
permanent: false,
},
]
},
}
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
next.config.js
module.exports = {
async redirects() {
return [
{
// this will match `/english(default)/something` being requested
source: '/english\\(default\\)/:slug',
destination: '/en-us/:slug',
permanent: false,
},
]
},
}
[Header, Cookie, and Query Matching](#header-cookie-and-query-matching)
-----------------------------------------------------------------------
To only match a redirect when header, cookie, or query values also match the `has` field or don't match the `missing` field can be used. Both the `source` and all `has` items must match and all `missing` items must not match for the redirect to be applied.
`has` and `missing` items can have the following fields:
* `type`: `String` - must be either `header`, `cookie`, `host`, or `query`.
* `key`: `String` - the key from the selected type to match against.
* `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.
next.config.js
module.exports = {
async redirects() {
return [
// if the header `x-redirect-me` is present,
// this redirect will be applied
{
source: '/:path((?!another-page$).*)',
has: [
{
type: 'header',
key: 'x-redirect-me',
},
],
permanent: false,
destination: '/another-page',
},
// if the header `x-dont-redirect` is present,
// this redirect will NOT be applied
{
source: '/:path((?!another-page$).*)',
missing: [
{
type: 'header',
key: 'x-do-not-redirect',
},
],
permanent: false,
destination: '/another-page',
},
// if the source, query, and cookie are matched,
// this redirect will be applied
{
source: '/specific/:path*',
has: [
{
type: 'query',
key: 'page',
// the page value will not be available in the
// destination since value is provided and doesn't
// use a named capture group e.g. (?<page>home)
value: 'home',
},
{
type: 'cookie',
key: 'authorized',
value: 'true',
},
],
permanent: false,
destination: '/another/:path*',
},
// if the header `x-authorized` is present and
// contains a matching value, this redirect will be applied
{
source: '/',
has: [
{
type: 'header',
key: 'x-authorized',
value: '(?<authorized>yes|true)',
},
],
permanent: false,
destination: '/home?authorized=:authorized',
},
// if the host is `example.com`,
// this redirect will be applied
{
source: '/:path((?!another-page$).*)',
has: [
{
type: 'host',
value: 'example.com',
},
],
permanent: false,
destination: '/another-page',
},
]
},
}
### [Redirects with basePath support](#redirects-with-basepath-support)
When leveraging [`basePath` support](/docs/app/api-reference/next-config-js/basePath) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect:
next.config.js
module.exports = {
basePath: '/docs',
async redirects() {
return [
{
source: '/with-basePath', // automatically becomes /docs/with-basePath
destination: '/another', // automatically becomes /docs/another
permanent: false,
},
{
// does not add /docs since basePath: false is set
source: '/without-basePath',
destination: 'https://example.com',
basePath: false,
permanent: false,
},
]
},
}
### [Redirects with i18n support](#redirects-with-i18n-support)
When leveraging [`i18n` support](/docs/pages/building-your-application/routing/internationalization) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.
next.config.js
module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
defaultLocale: 'en',
},
async redirects() {
return [
{
source: '/with-locale', // automatically handles all locales
destination: '/another', // automatically passes the locale on
permanent: false,
},
{
// does not handle locales automatically since locale: false is set
source: '/nl/with-locale-manual',
destination: '/nl/another',
locale: false,
permanent: false,
},
{
// this matches '/' since `en` is the defaultLocale
source: '/en',
destination: '/en/another',
locale: false,
permanent: false,
},
// it's possible to match all locales even when locale: false is set
{
source: '/:locale/page',
destination: '/en/newpage',
permanent: false,
locale: false,
},
{
// this gets converted to /(en|fr|de)/(.*) so will not match the top-level
// `/` or `/fr` routes like /:path* would
source: '/(.*)',
destination: '/another',
permanent: false,
},
]
},
}
In some rare cases, you might need to assign a custom status code for older HTTP Clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both. To to ensure IE11 compatibility, a `Refresh` header is automatically added for the 308 status code.
[Other Redirects](#other-redirects)
-----------------------------------
* Inside [API Routes](/docs/pages/building-your-application/routing/api-routes) and [Route Handlers](/docs/app/building-your-application/routing/route-handlers), you can redirect based on the incoming request.
* Inside [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) and [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props), you can redirect specific pages at request-time.
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.3.0`
`missing` added.
`v10.2.0`
`has` added.
`v9.5.0`
`redirects` added.
[Previous
reactStrictMode
](/docs/pages/api-reference/next-config-js/reactStrictMode)
[Next
rewrites
](/docs/pages/api-reference/next-config-js/rewrites)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"44a2fafa03608923872d44f99968fc55\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/transpilePackages | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [
transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Version History](#version-history)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/transpilePackages.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)transpilePackages
transpilePackages
=================
Next.js can automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (`node_modules`). This replaces the `next-transpile-modules` package.
next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@acme/ui', 'lodash-es'],
}
module.exports = nextConfig
[Version History](#version-history)
-----------------------------------
Version
Changes
`v13.0.0`
`transpilePackages` added.
[Previous
trailingSlash
](/docs/pages/api-reference/next-config-js/trailingSlash)
[Next
turbo
](/docs/pages/api-reference/next-config-js/turbo)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"933baed4eec0a2074f929998c02b91f7\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/turbo | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [
turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [webpack loaders](#webpack-loaders)
* [Supported loaders](#supported-loaders)
* [Resolve aliases](#resolve-aliases)
* [Resolve extensions](#resolve-extensions)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/turbo.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)turbo
turbo (experimental)
====================
Turbopack can be customized to transform different files and change how modules are resolved.
> **Good to know**:
>
> * These features are experimental and will only work with `next --turbo`.
> * Turbopack for Next.js does not require loaders nor loader configuration for built-in functionality. Turbopack has built-in support for css and compiling modern JavaScript, so there's no need for `css-loader`, `postcss-loader`, or `babel-loader` if you're using `@babel/preset-env`.
[webpack loaders](#webpack-loaders)
-----------------------------------
If you need loader support beyond what's built in, many webpack loaders already work with Turbopack. There are currently some limitations:
* Only a core subset of the webpack loader API is implemented. Currently, there is enough coverage for some popular loaders, and we'll expand our API support in the future.
* Only loaders that return JavaScript code are supported. Loaders that transform files like stylesheets or images are not currently supported.
* Options passed to webpack loaders must be plain JavaScript primitives, objects, and arrays. For example, it's not possible to pass `require()`d plugin modules as option values.
To configure loaders, add the names of the loaders you've installed and any options in `next.config.js`, mapping file extensions to a list of loaders:
next.config.js
module.exports = {
experimental: {
turbo: {
rules: {
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js',
},
},
},
},
}
> **Good to know**: Prior to Next.js version 13.4.4, `experimental.turbo.rules` was named `experimental.turbo.loaders` and only accepted file extensions like `.mdx` instead of `*.mdx`.
### [Supported loaders](#supported-loaders)
The following loaders have been tested to work with Turbopack's webpack loader implementation:
* [`babel-loader`](https://www.npmjs.com/package/babel-loader)
* [`@svgr/webpack`](https://www.npmjs.com/package/@svgr/webpack)
* [`svg-inline-loader`](https://www.npmjs.com/package/svg-inline-loader)
* [`yaml-loader`](https://www.npmjs.com/package/yaml-loader)
* [`string-replace-loader`](https://www.npmjs.com/package/string-replace-loader)
* [`raw-loader`](https://www.npmjs.com/package/raw-loader)
* ['sass-loader'](https://www.npmjs.com/package/sass-loader)
[Resolve aliases](#resolve-aliases)
-----------------------------------
Through `next.config.js`, Turbopack can be configured to modify module resolution through aliases, similar to webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) configuration.
To configure resolve aliases, map imported patterns to their new destination in `next.config.js`:
next.config.js
module.exports = {
experimental: {
turbo: {
resolveAlias: {
underscore: 'lodash',
mocha: { browser: 'mocha/browser-entry.js' },
},
},
},
}
This aliases imports of the `underscore` package to the `lodash` package. In other words, `import underscore from 'underscore'` will load the `lodash` module instead of `underscore`.
Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `mocha` module will be aliased to `mocha/browser-entry.js` when Turbopack targets browser environments.
[Resolve extensions](#resolve-extensions)
-----------------------------------------
Through `next.config.js`, Turbopack can be configured to resolve modules with custom extensions, similar to webpack's [`resolve.extensions`](https://webpack.js.org/configuration/resolve/#resolveextensions) configuration.
To configure resolve extensions, use the `resolveExtensions` field in `next.config.js`:
next.config.js
module.exports = {
experimental: {
turbo: {
resolveExtensions: [
'.mdx',
'.tsx',
'.ts',
'.jsx',
'.js',
'.mjs',
'.json',
],
},
},
}
This overwrites the original resolve extensions with the provided list. Make sure to include the default extensions.
For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack).
[Previous
transpilePackages
](/docs/pages/api-reference/next-config-js/transpilePackages)
[Next
typescript
](/docs/pages/api-reference/next-config-js/typescript)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"1f23cd8e3217ba9f3a7a93775cb98fa8\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/urlImports | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [
urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
On this page
* [Security Model](#security-model)
* [Lockfile](#lockfile)
* [Examples](#examples)
* [Skypack](#skypack)
* [Static Image Imports](#static-image-imports)
* [URLs in CSS](#urls-in-css)
* [Asset Imports](#asset-imports)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/urlImports.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)urlImports
urlImports
==========
URL imports are an experimental feature that allows you to import modules directly from external servers (instead of from the local disk).
> **Warning**: This feature is experimental. Only use domains that you trust to download and execute on your machine. Please exercise discretion, and caution until the feature is flagged as stable.
To opt-in, add the allowed URL prefixes inside `next.config.js`:
next.config.js
module.exports = {
experimental: {
urlImports: ['https://example.com/assets/', 'https://cdn.skypack.dev'],
},
}
Then, you can import modules directly from URLs:
import { a, b, c } from 'https://example.com/assets/some/module.js'
URL Imports can be used everywhere normal package imports can be used.
[Security Model](#security-model)
---------------------------------
This feature is being designed with **security as the top priority**. To start, we added an experimental flag forcing you to explicitly allow the domains you accept URL imports from. We're working to take this further by limiting URL imports to execute in the browser sandbox using the [Edge Runtime](/docs/app/api-reference/edge).
[Lockfile](#lockfile)
---------------------
When using URL imports, Next.js will create a `next.lock` directory containing a lockfile and fetched assets. This directory **must be committed to Git**, not ignored by `.gitignore`.
* When running `next dev`, Next.js will download and add all newly discovered URL Imports to your lockfile
* When running `next build`, Next.js will use only the lockfile to build the application for production
Typically, no network requests are needed and any outdated lockfile will cause the build to fail. One exception is resources that respond with `Cache-Control: no-cache`. These resources will have a `no-cache` entry in the lockfile and will always be fetched from the network on each build.
[Examples](#examples)
---------------------
### [Skypack](#skypack)
import confetti from 'https://cdn.skypack.dev/canvas-confetti'
import { useEffect } from 'react'
export default () => {
useEffect(() => {
confetti()
})
return <p>Hello</p>
}
### [Static Image Imports](#static-image-imports)
import Image from 'next/image'
import logo from 'https://example.com/assets/logo.png'
export default () => (
<div>
<Image src={logo} placeholder="blur" />
</div>
)
### [URLs in CSS](#urls-in-css)
.className {
background: url('https://example.com/assets/hero.jpg');
}
### [Asset Imports](#asset-imports)
const logo = new URL('https://example.com/assets/file.txt', import.meta.url)
console.log(logo.pathname)
// prints "/_next/static/media/file.a9727b5d.txt"
[Previous
typescript
](/docs/pages/api-reference/next-config-js/typescript)
[Next
webpack
](/docs/pages/api-reference/next-config-js/webpack)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"c074e55ebbaae87df87c33d2612edb6d\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/pages/api-reference/next-config-js/runtime-configuration | Menu
Using Pages Router
Features available in /pages
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [
Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/03-pages/02-api-reference/03-next-config-js/runtime-configuration.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[Pages Router](/docs/pages)[...](/docs/pages/api-reference)[next.config.js Options](/docs/pages/api-reference/next-config-js)Runtime Config
Runtime Config
==============
> **Warning:**
>
> * **This feature is deprecated.** We recommend using [environment variables](/docs/pages/building-your-application/configuring/environment-variables) instead, which also can support reading runtime values.
> * You can run code on server startup using the [`register` function](/docs/app/building-your-application/optimizing/instrumentation).
> * This feature does not work with [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization), [Output File Tracing](/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files), or [React Server Components](/docs/app/building-your-application/rendering/server-components).
To add runtime configuration to your app, open `next.config.js` and add the `publicRuntimeConfig` and `serverRuntimeConfig` configs:
next.config.js
module.exports = {
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: 'secret',
secondSecret: process.env.SECOND_SECRET, // Pass through env variables
},
publicRuntimeConfig: {
// Will be available on both server and client
staticFolder: '/static',
},
}
Place any server-only runtime config under `serverRuntimeConfig`.
Anything accessible to both client and server-side code should be under `publicRuntimeConfig`.
> A page that relies on `publicRuntimeConfig` **must** use `getInitialProps` or `getServerSideProps` or your application must have a [Custom App](/docs/pages/building-your-application/routing/custom-app) with `getInitialProps` to opt-out of [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization). Runtime configuration won't be available to any page (or component in a page) without being server-side rendered.
To get access to the runtime configs in your app use `next/config`, like so:
import getConfig from 'next/config'
import Image from 'next/image'
// Only holds serverRuntimeConfig and publicRuntimeConfig
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
// Will only be available on the server-side
console.log(serverRuntimeConfig.mySecret)
// Will be available on both server-side and client-side
console.log(publicRuntimeConfig.staticFolder)
function MyImage() {
return (
<div>
<Image
src={`${publicRuntimeConfig.staticFolder}/logo.png`}
alt="logo"
layout="fill"
/>
</div>
)
}
export default MyImage
[Previous
rewrites
](/docs/pages/api-reference/next-config-js/rewrites)
[Next
trailingSlash
](/docs/pages/api-reference/next-config-js/trailingSlash)
Was this helpful?
supported.
Send |
{
"contentLength": null,
"etag": "W/\"7681569c5b4a185b3900a89345cebba7\"",
"lastModifiedHeader": null,
"lastModifiedHtml": null
} | https://nextjs.org/docs/app/api-reference/next-config-js/poweredByHeader | Menu
Using App Router
Features available in /app
* [Getting Started](/docs/getting-started)
* [Installation](/docs/getting-started/installation)
* [Project Structure](/docs/getting-started/project-structure)
* [Building Your Application](/docs/app/building-your-application)
* [Routing](/docs/app/building-your-application/routing)
* [Defining Routes](/docs/app/building-your-application/routing/defining-routes)
* [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)
* [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)
* [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)
* [Error Handling](/docs/app/building-your-application/routing/error-handling)
* [Redirecting](/docs/app/building-your-application/routing/redirecting)
* [Route Groups](/docs/app/building-your-application/routing/route-groups)
* [Project Organization](/docs/app/building-your-application/routing/colocation)
* [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)
* [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)
* [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)
* [Route Handlers](/docs/app/building-your-application/routing/route-handlers)
* [Middleware](/docs/app/building-your-application/routing/middleware)
* [Internationalization](/docs/app/building-your-application/routing/internationalization)
* [Data Fetching](/docs/app/building-your-application/data-fetching)
* [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
* [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
* [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)
* [Rendering](/docs/app/building-your-application/rendering)
* [Server Components](/docs/app/building-your-application/rendering/server-components)
* [Client Components](/docs/app/building-your-application/rendering/client-components)
* [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)
* [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Caching](/docs/app/building-your-application/caching)
* [Styling](/docs/app/building-your-application/styling)
* [CSS Modules](/docs/app/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
* [Sass](/docs/app/building-your-application/styling/sass)
* [Optimizing](/docs/app/building-your-application/optimizing)
* [Images](/docs/app/building-your-application/optimizing/images)
* [Videos](/docs/app/building-your-application/optimizing/videos)
* [Fonts](/docs/app/building-your-application/optimizing/fonts)
* [Metadata](/docs/app/building-your-application/optimizing/metadata)
* [Scripts](/docs/app/building-your-application/optimizing/scripts)
* [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)
* [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)
* [Analytics](/docs/app/building-your-application/optimizing/analytics)
* [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)
* [Static Assets](/docs/app/building-your-application/optimizing/static-assets)
* [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)
* [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)
* [Configuring](/docs/app/building-your-application/configuring)
* [TypeScript](/docs/app/building-your-application/configuring/typescript)
* [ESLint](/docs/app/building-your-application/configuring/eslint)
* [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)
* [MDX](/docs/app/building-your-application/configuring/mdx)
* [src Directory](/docs/app/building-your-application/configuring/src-directory)
* [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
* [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)
* [Testing](/docs/app/building-your-application/testing)
* [Vitest](/docs/app/building-your-application/testing/vitest)
* [Jest](/docs/app/building-your-application/testing/jest)
* [Playwright](/docs/app/building-your-application/testing/playwright)
* [Cypress](/docs/app/building-your-application/testing/cypress)
* [Authentication](/docs/app/building-your-application/authentication)
* [Deploying](/docs/app/building-your-application/deploying)
* [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/app/building-your-application/deploying/static-exports)
* [Upgrading](/docs/app/building-your-application/upgrading)
* [Codemods](/docs/app/building-your-application/upgrading/codemods)
* [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)
* [Version 14](/docs/app/building-your-application/upgrading/version-14)
* [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)
* [API Reference](/docs/app/api-reference)
* [Components](/docs/app/api-reference/components)
* [Font](/docs/app/api-reference/components/font)
* [<Image>](/docs/app/api-reference/components/image)
* [<Link>](/docs/app/api-reference/components/link)
* [<Script>](/docs/app/api-reference/components/script)
* [File Conventions](/docs/app/api-reference/file-conventions)
* [default.js](/docs/app/api-reference/file-conventions/default)
* [error.js](/docs/app/api-reference/file-conventions/error)
* [instrumentation.js](/docs/app/api-reference/file-conventions/instrumentation)
* [layout.js](/docs/app/api-reference/file-conventions/layout)
* [loading.js](/docs/app/api-reference/file-conventions/loading)
* [middleware.js](/docs/app/api-reference/file-conventions/middleware)
* [not-found.js](/docs/app/api-reference/file-conventions/not-found)
* [page.js](/docs/app/api-reference/file-conventions/page)
* [route.js](/docs/app/api-reference/file-conventions/route)
* [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config)
* [template.js](/docs/app/api-reference/file-conventions/template)
* [Metadata Files](/docs/app/api-reference/file-conventions/metadata)
* [favicon, icon, and apple-icon](/docs/app/api-reference/file-conventions/metadata/app-icons)
* [manifest.json](/docs/app/api-reference/file-conventions/metadata/manifest)
* [opengraph-image and twitter-image](/docs/app/api-reference/file-conventions/metadata/opengraph-image)
* [robots.txt](/docs/app/api-reference/file-conventions/metadata/robots)
* [sitemap.xml](/docs/app/api-reference/file-conventions/metadata/sitemap)
* [Functions](/docs/app/api-reference/functions)
* [cookies](/docs/app/api-reference/functions/cookies)
* [draftMode](/docs/app/api-reference/functions/draft-mode)
* [fetch](/docs/app/api-reference/functions/fetch)
* [generateImageMetadata](/docs/app/api-reference/functions/generate-image-metadata)
* [generateMetadata](/docs/app/api-reference/functions/generate-metadata)
* [generateSitemaps](/docs/app/api-reference/functions/generate-sitemaps)
* [generateStaticParams](/docs/app/api-reference/functions/generate-static-params)
* [generateViewport](/docs/app/api-reference/functions/generate-viewport)
* [headers](/docs/app/api-reference/functions/headers)
* [ImageResponse](/docs/app/api-reference/functions/image-response)
* [NextRequest](/docs/app/api-reference/functions/next-request)
* [NextResponse](/docs/app/api-reference/functions/next-response)
* [notFound](/docs/app/api-reference/functions/not-found)
* [permanentRedirect](/docs/app/api-reference/functions/permanentRedirect)
* [redirect](/docs/app/api-reference/functions/redirect)
* [revalidatePath](/docs/app/api-reference/functions/revalidatePath)
* [revalidateTag](/docs/app/api-reference/functions/revalidateTag)
* [unstable\_cache](/docs/app/api-reference/functions/unstable_cache)
* [unstable\_noStore](/docs/app/api-reference/functions/unstable_noStore)
* [useParams](/docs/app/api-reference/functions/use-params)
* [usePathname](/docs/app/api-reference/functions/use-pathname)
* [useReportWebVitals](/docs/app/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/app/api-reference/functions/use-router)
* [useSearchParams](/docs/app/api-reference/functions/use-search-params)
* [useSelectedLayoutSegment](/docs/app/api-reference/functions/use-selected-layout-segment)
* [useSelectedLayoutSegments](/docs/app/api-reference/functions/use-selected-layout-segments)
* [userAgent](/docs/app/api-reference/functions/userAgent)
* [next.config.js Options](/docs/app/api-reference/next-config-js)
* [appDir](/docs/app/api-reference/next-config-js/appDir)
* [assetPrefix](/docs/app/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/app/api-reference/next-config-js/basePath)
* [compress](/docs/app/api-reference/next-config-js/compress)
* [crossOrigin](/docs/app/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/app/api-reference/next-config-js/devIndicators)
* [distDir](/docs/app/api-reference/next-config-js/distDir)
* [env](/docs/app/api-reference/next-config-js/env)
* [eslint](/docs/app/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/app/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/app/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/app/api-reference/next-config-js/generateEtags)
* [headers](/docs/app/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/app/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/app/api-reference/next-config-js/images)
* [cacheHandler](/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath)
* [instrumentationHook](/docs/app/api-reference/next-config-js/instrumentationHook)
* [logging](/docs/app/api-reference/next-config-js/logging)
* [mdxRs](/docs/app/api-reference/next-config-js/mdxRs)
* [onDemandEntries](/docs/app/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/app/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/app/api-reference/next-config-js/output)
* [pageExtensions](/docs/app/api-reference/next-config-js/pageExtensions)
* [Partial Prerendering (experimental)](/docs/app/api-reference/next-config-js/partial-prerendering)
* [
poweredByHeader](/docs/app/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/app/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/app/api-reference/next-config-js/redirects)
* [rewrites](/docs/app/api-reference/next-config-js/rewrites)
* [serverActions](/docs/app/api-reference/next-config-js/serverActions)
* [serverComponentsExternalPackages](/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
* [StaleTimes (experimental)](/docs/app/api-reference/next-config-js/staleTimes)
* [trailingSlash](/docs/app/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/app/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/app/api-reference/next-config-js/turbo)
* [typedRoutes](/docs/app/api-reference/next-config-js/typedRoutes)
* [typescript](/docs/app/api-reference/next-config-js/typescript)
* [urlImports](/docs/app/api-reference/next-config-js/urlImports)
* [webpack](/docs/app/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/app/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/app/api-reference/create-next-app)
* [Edge Runtime](/docs/app/api-reference/edge)
* [Next.js CLI](/docs/app/api-reference/next-cli)
* [Building Your Application](/docs/pages/building-your-application)
* [Routing](/docs/pages/building-your-application/routing)
* [Pages and Layouts](/docs/pages/building-your-application/routing/pages-and-layouts)
* [Dynamic Routes](/docs/pages/building-your-application/routing/dynamic-routes)
* [Linking and Navigating](/docs/pages/building-your-application/routing/linking-and-navigating)
* [Redirecting](/docs/pages/building-your-application/routing/redirecting)
* [Custom App](/docs/pages/building-your-application/routing/custom-app)
* [Custom Document](/docs/pages/building-your-application/routing/custom-document)
* [API Routes](/docs/pages/building-your-application/routing/api-routes)
* [Custom Errors](/docs/pages/building-your-application/routing/custom-error)
* [Internationalization](/docs/pages/building-your-application/routing/internationalization)
* [Middleware](/docs/pages/building-your-application/routing/middleware)
* [Rendering](/docs/pages/building-your-application/rendering)
* [Server-side Rendering (SSR)](/docs/pages/building-your-application/rendering/server-side-rendering)
* [Static Site Generation (SSG)](/docs/pages/building-your-application/rendering/static-site-generation)
* [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization)
* [Client-side Rendering (CSR)](/docs/pages/building-your-application/rendering/client-side-rendering)
* [Edge and Node.js Runtimes](/docs/pages/building-your-application/rendering/edge-and-nodejs-runtimes)
* [Data Fetching](/docs/pages/building-your-application/data-fetching)
* [getStaticProps](/docs/pages/building-your-application/data-fetching/get-static-props)
* [getStaticPaths](/docs/pages/building-your-application/data-fetching/get-static-paths)
* [Forms and Mutations](/docs/pages/building-your-application/data-fetching/forms-and-mutations)
* [getServerSideProps](/docs/pages/building-your-application/data-fetching/get-server-side-props)
* [Incremental Static Regeneration (ISR)](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
* [Client-side Fetching](/docs/pages/building-your-application/data-fetching/client-side)
* [Styling](/docs/pages/building-your-application/styling)
* [CSS Modules](/docs/pages/building-your-application/styling/css-modules)
* [Tailwind CSS](/docs/pages/building-your-application/styling/tailwind-css)
* [CSS-in-JS](/docs/pages/building-your-application/styling/css-in-js)
* [Sass](/docs/pages/building-your-application/styling/sass)
* [Optimizing](/docs/pages/building-your-application/optimizing)
* [Images](/docs/pages/building-your-application/optimizing/images)
* [Fonts](/docs/pages/building-your-application/optimizing/fonts)
* [Scripts](/docs/pages/building-your-application/optimizing/scripts)
* [Static Assets](/docs/pages/building-your-application/optimizing/static-assets)
* [Bundle Analyzer](/docs/pages/building-your-application/optimizing/bundle-analyzer)
* [Analytics](/docs/pages/building-your-application/optimizing/analytics)
* [Lazy Loading](/docs/pages/building-your-application/optimizing/lazy-loading)
* [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation)
* [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)
* [Third Party Libraries](/docs/pages/building-your-application/optimizing/third-party-libraries)
* [Configuring](/docs/pages/building-your-application/configuring)
* [TypeScript](/docs/pages/building-your-application/configuring/typescript)
* [ESLint](/docs/pages/building-your-application/configuring/eslint)
* [Environment Variables](/docs/pages/building-your-application/configuring/environment-variables)
* [Absolute Imports and Module Path Aliases](/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases)
* [src Directory](/docs/pages/building-your-application/configuring/src-directory)
* [MDX](/docs/pages/building-your-application/configuring/mdx)
* [AMP](/docs/pages/building-your-application/configuring/amp)
* [Babel](/docs/pages/building-your-application/configuring/babel)
* [PostCSS](/docs/pages/building-your-application/configuring/post-css)
* [Custom Server](/docs/pages/building-your-application/configuring/custom-server)
* [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
* [Error Handling](/docs/pages/building-your-application/configuring/error-handling)
* [Debugging](/docs/pages/building-your-application/configuring/debugging)
* [Preview Mode](/docs/pages/building-your-application/configuring/preview-mode)
* [Content Security Policy](/docs/pages/building-your-application/configuring/content-security-policy)
* [Testing](/docs/pages/building-your-application/testing)
* [Vitest](/docs/pages/building-your-application/testing/vitest)
* [Jest](/docs/pages/building-your-application/testing/jest)
* [Playwright](/docs/pages/building-your-application/testing/playwright)
* [Cypress](/docs/pages/building-your-application/testing/cypress)
* [Authentication](/docs/pages/building-your-application/authentication)
* [Deploying](/docs/pages/building-your-application/deploying)
* [Production Checklist](/docs/pages/building-your-application/deploying/production-checklist)
* [Static Exports](/docs/pages/building-your-application/deploying/static-exports)
* [Multi Zones](/docs/pages/building-your-application/deploying/multi-zones)
* [Continuous Integration (CI) Build Caching](/docs/pages/building-your-application/deploying/ci-build-caching)
* [Upgrading](/docs/pages/building-your-application/upgrading)
* [Codemods](/docs/pages/building-your-application/upgrading/codemods)
* [From Pages to App](/docs/pages/building-your-application/upgrading/app-router-migration)
* [Migrating from Vite](/docs/pages/building-your-application/upgrading/from-vite)
* [Migrating from Create React App](/docs/pages/building-your-application/upgrading/from-create-react-app)
* [Version 14](/docs/pages/building-your-application/upgrading/version-14)
* [Version 13](/docs/pages/building-your-application/upgrading/version-13)
* [Version 12](/docs/pages/building-your-application/upgrading/version-12)
* [Version 11](/docs/pages/building-your-application/upgrading/version-11)
* [Version 10](/docs/pages/building-your-application/upgrading/version-10)
* [Version 9](/docs/pages/building-your-application/upgrading/version-9)
* [API Reference](/docs/pages/api-reference)
* [Components](/docs/pages/api-reference/components)
* [Font](/docs/pages/api-reference/components/font)
* [<Head>](/docs/pages/api-reference/components/head)
* [<Image>](/docs/pages/api-reference/components/image)
* [<Image> (Legacy)](/docs/pages/api-reference/components/image-legacy)
* [<Link>](/docs/pages/api-reference/components/link)
* [<Script>](/docs/pages/api-reference/components/script)
* [Functions](/docs/pages/api-reference/functions)
* [getInitialProps](/docs/pages/api-reference/functions/get-initial-props)
* [getServerSideProps](/docs/pages/api-reference/functions/get-server-side-props)
* [getStaticPaths](/docs/pages/api-reference/functions/get-static-paths)
* [getStaticProps](/docs/pages/api-reference/functions/get-static-props)
* [NextRequest](/docs/pages/api-reference/functions/next-request)
* [NextResponse](/docs/pages/api-reference/functions/next-response)
* [useAmp](/docs/pages/api-reference/functions/use-amp)
* [useReportWebVitals](/docs/pages/api-reference/functions/use-report-web-vitals)
* [useRouter](/docs/pages/api-reference/functions/use-router)
* [userAgent](/docs/pages/api-reference/functions/userAgent)
* [next.config.js Options](/docs/pages/api-reference/next-config-js)
* [assetPrefix](/docs/pages/api-reference/next-config-js/assetPrefix)
* [basePath](/docs/pages/api-reference/next-config-js/basePath)
* [compress](/docs/pages/api-reference/next-config-js/compress)
* [crossOrigin](/docs/pages/api-reference/next-config-js/crossOrigin)
* [devIndicators](/docs/pages/api-reference/next-config-js/devIndicators)
* [distDir](/docs/pages/api-reference/next-config-js/distDir)
* [env](/docs/pages/api-reference/next-config-js/env)
* [eslint](/docs/pages/api-reference/next-config-js/eslint)
* [exportPathMap](/docs/pages/api-reference/next-config-js/exportPathMap)
* [generateBuildId](/docs/pages/api-reference/next-config-js/generateBuildId)
* [generateEtags](/docs/pages/api-reference/next-config-js/generateEtags)
* [headers](/docs/pages/api-reference/next-config-js/headers)
* [httpAgentOptions](/docs/pages/api-reference/next-config-js/httpAgentOptions)
* [images](/docs/pages/api-reference/next-config-js/images)
* [instrumentationHook](/docs/pages/api-reference/next-config-js/instrumentationHook)
* [onDemandEntries](/docs/pages/api-reference/next-config-js/onDemandEntries)
* [optimizePackageImports](/docs/pages/api-reference/next-config-js/optimizePackageImports)
* [output](/docs/pages/api-reference/next-config-js/output)
* [pageExtensions](/docs/pages/api-reference/next-config-js/pageExtensions)
* [poweredByHeader](/docs/pages/api-reference/next-config-js/poweredByHeader)
* [productionBrowserSourceMaps](/docs/pages/api-reference/next-config-js/productionBrowserSourceMaps)
* [reactStrictMode](/docs/pages/api-reference/next-config-js/reactStrictMode)
* [redirects](/docs/pages/api-reference/next-config-js/redirects)
* [rewrites](/docs/pages/api-reference/next-config-js/rewrites)
* [Runtime Config](/docs/pages/api-reference/next-config-js/runtime-configuration)
* [trailingSlash](/docs/pages/api-reference/next-config-js/trailingSlash)
* [transpilePackages](/docs/pages/api-reference/next-config-js/transpilePackages)
* [turbo](/docs/pages/api-reference/next-config-js/turbo)
* [typescript](/docs/pages/api-reference/next-config-js/typescript)
* [urlImports](/docs/pages/api-reference/next-config-js/urlImports)
* [webpack](/docs/pages/api-reference/next-config-js/webpack)
* [webVitalsAttribution](/docs/pages/api-reference/next-config-js/webVitalsAttribution)
* [create-next-app](/docs/pages/api-reference/create-next-app)
* [Next.js CLI](/docs/pages/api-reference/next-cli)
* [Edge Runtime](/docs/pages/api-reference/edge)
* [Architecture](/docs/architecture)
* [Accessibility](/docs/architecture/accessibility)
* [Fast Refresh](/docs/architecture/fast-refresh)
* [Next.js Compiler](/docs/architecture/nextjs-compiler)
* [Supported Browsers](/docs/architecture/supported-browsers)
* [Turbopack](/docs/architecture/turbopack)
* [Community](/docs/community)
* [Contribution Guide](/docs/community/contribution-guide)
[Edit this page on GitHub](https://github.com/vercel/next.js/edit/canary/docs/02-app/02-api-reference/05-next-config-js/poweredByHeader.mdx) [Managed Next.js (Vercel)](https://vercel.com/solutions/nextjs?utm_source=next_site&utm_medium=web&utm_campaign=managed_nextjs_solutions_page) Scroll to top
[App Router](/docs/app)[...](/docs/app/api-reference)[next.config.js Options](/docs/app/api-reference/next-config-js)poweredByHeader
poweredByHeader
===============
By default Next.js will add the `x-powered-by` header. To opt-out of it, open `next.config.js` and disable the `poweredByHeader` config:
next.config.js
module.exports = {
poweredByHeader: false,
}
[Previous
Partial Prerendering (experimental)
](/docs/app/api-reference/next-config-js/partial-prerendering)
[Next
productionBrowserSourceMaps
](/docs/app/api-reference/next-config-js/productionBrowserSourceMaps)
Was this helpful?
supported.
Send |