Unverified Commit 76ade73d authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

docs: Move optimizing pages to guides (#78500)

parent dba20c3d
...@@ -31,22 +31,22 @@ Top-level folders are used to organize your application's code and static assets ...@@ -31,22 +31,22 @@ Top-level folders are used to organize your application's code and static assets
Top-level files are used to configure your application, manage dependencies, run middleware, integrate monitoring tools, and define environment variables. Top-level files are used to configure your application, manage dependencies, run middleware, integrate monitoring tools, and define environment variables.
| | | | | |
| -------------------------------------------------------------------------------------- | --------------------------------------- | | ---------------------------------------------------------------------------- | --------------------------------------- |
| **Next.js** | | | **Next.js** | |
| [`next.config.js`](/docs/app/api-reference/config/next-config-js) | Configuration file for Next.js | | [`next.config.js`](/docs/app/api-reference/config/next-config-js) | Configuration file for Next.js |
| [`package.json`](/docs/app/getting-started/installation#manual-installation) | Project dependencies and scripts | | [`package.json`](/docs/app/getting-started/installation#manual-installation) | Project dependencies and scripts |
| [`instrumentation.ts`](/docs/app/building-your-application/optimizing/instrumentation) | OpenTelemetry and Instrumentation file | | [`instrumentation.ts`](/docs/app/guides/instrumentation) | OpenTelemetry and Instrumentation file |
| [`middleware.ts`](/docs/app/building-your-application/routing/middleware) | Next.js request middleware | | [`middleware.ts`](/docs/app/building-your-application/routing/middleware) | Next.js request middleware |
| [`.env`](/docs/app/guides/environment-variables) | Environment variables | | [`.env`](/docs/app/guides/environment-variables) | Environment variables |
| [`.env.local`](/docs/app/guides/environment-variables) | Local environment variables | | [`.env.local`](/docs/app/guides/environment-variables) | Local environment variables |
| [`.env.production`](/docs/app/guides/environment-variables) | Production environment variables | | [`.env.production`](/docs/app/guides/environment-variables) | Production environment variables |
| [`.env.development`](/docs/app/guides/environment-variables) | Development environment variables | | [`.env.development`](/docs/app/guides/environment-variables) | Development environment variables |
| [`.eslintrc.json`](/docs/app/api-reference/config/eslint) | Configuration file for ESLint | | [`.eslintrc.json`](/docs/app/api-reference/config/eslint) | Configuration file for ESLint |
| `.gitignore` | Git files and folders to ignore | | `.gitignore` | Git files and folders to ignore |
| `next-env.d.ts` | TypeScript declaration file for Next.js | | `next-env.d.ts` | TypeScript declaration file for Next.js |
| `tsconfig.json` | Configuration file for TypeScript | | `tsconfig.json` | Configuration file for TypeScript |
| `jsconfig.json` | Configuration file for JavaScript | | `jsconfig.json` | Configuration file for JavaScript |
<AppOnly> <AppOnly>
......
--- ---
title: Analytics title: How to add analytics to your Next.js application
nav_title: Analytics
description: Measure and track page performance using Next.js Speed Insights description: Measure and track page performance using Next.js Speed Insights
--- ---
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
Next.js has built-in support for measuring and reporting performance metrics. You can either use the `useReportWebVitals` hook to manage reporting yourself, or alternatively, Vercel provides a [managed service](https://vercel.com/analytics?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) to automatically collect and visualize metrics for you. Next.js has built-in support for measuring and reporting performance metrics. You can either use the [`useReportWebVitals`](/docs/app/api-reference/functions/use-report-web-vitals) hook to manage reporting yourself, or alternatively, Vercel provides a [managed service](https://vercel.com/analytics?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) to automatically collect and visualize metrics for you.
## Client Instrumentation ## Client Instrumentation
......
...@@ -227,7 +227,7 @@ This allows you to use a singular Docker image that can be promoted through mult ...@@ -227,7 +227,7 @@ This allows you to use a singular Docker image that can be promoted through mult
**Good to know:** **Good to know:**
- You can run code on server startup using the [`register` function](/docs/app/building-your-application/optimizing/instrumentation). - You can run code on server startup using the [`register` function](/docs/app/guides/instrumentation).
- We do not recommend using the [`runtimeConfig`](/docs/pages/api-reference/config/next-config-js/runtime-configuration) option, as this does not work with the standalone output mode. Instead, we recommend [incrementally adopting](/docs/app/guides/migrating/app-router-migration) the App Router if you need this feature. - We do not recommend using the [`runtimeConfig`](/docs/pages/api-reference/config/next-config-js/runtime-configuration) option, as this does not work with the standalone output mode. Instead, we recommend [incrementally adopting](/docs/app/guides/migrating/app-router-migration) the App Router if you need this feature.
## Environment Variables on Vercel ## Environment Variables on Vercel
......
--- ---
title: Instrumentation title: How to set up instrumentation
nav_title: Instrumentation
description: Learn how to use instrumentation to run code at server startup in your Next.js app description: Learn how to use instrumentation to run code at server startup in your Next.js app
related: related:
title: Learn more about Instrumentation title: Learn more about Instrumentation
......
--- ---
title: Lazy Loading title: How to lazy load Client Components and libraries
nav_title: Lazy Loading
description: Lazy load imported libraries and React Components to improve your application's loading performance. description: Lazy load imported libraries and React Components to improve your application's loading performance.
--- ---
......
--- ---
title: Local Development title: How to optimize your local development environment
nav_title: Development Environment
description: Learn how to optimize your local development environment with Next.js. description: Learn how to optimize your local development environment with Next.js.
--- ---
...@@ -34,7 +35,7 @@ npm run dev --turbopack ...@@ -34,7 +35,7 @@ npm run dev --turbopack
### 3. Check your imports ### 3. Check your imports
The way you import code can greatly affect compilation and bundling time. Learn more about [optimizing package bundling](/docs/app/building-your-application/optimizing/package-bundling) and explore tools like [Dependency Cruiser](https://github.com/sverweij/dependency-cruiser) or [Madge](https://github.com/pahen/madge). The way you import code can greatly affect compilation and bundling time. Learn more about [optimizing package bundling](/docs/app/guides/package-bundling) and explore tools like [Dependency Cruiser](https://github.com/sverweij/dependency-cruiser) or [Madge](https://github.com/pahen/madge).
### Icon libraries ### Icon libraries
...@@ -122,7 +123,7 @@ Consider if you really need them for local development. You can optionally only ...@@ -122,7 +123,7 @@ Consider if you really need them for local development. You can optionally only
If your app is very large, it might need more memory. If your app is very large, it might need more memory.
[Learn more about optimizing memory usage](/docs/app/building-your-application/optimizing/memory-usage). [Learn more about optimizing memory usage](/docs/app/guides/memory-usage).
### 7. Server Components and data fetching ### 7. Server Components and data fetching
......
--- ---
title: Memory Usage title: How to optimize memory usage
nav_title: Memory Usage
description: Optimize memory used by your application in development and production. description: Optimize memory used by your application in development and production.
--- ---
...@@ -11,7 +12,7 @@ Let's explore some strategies and techniques to optimize memory and address comm ...@@ -11,7 +12,7 @@ Let's explore some strategies and techniques to optimize memory and address comm
Applications with a large amount of dependencies will use more memory. Applications with a large amount of dependencies will use more memory.
The [Bundle Analyzer](/docs/app/building-your-application/optimizing/package-bundling) can help you investigate large dependencies in your application that may be able to be removed to improve performance and memory usage. The [Bundle Analyzer](/docs/app/guides/package-bundling) can help you investigate large dependencies in your application that may be able to be removed to improve performance and memory usage.
## Try `experimental.webpackMemoryOptimizations` ## Try `experimental.webpackMemoryOptimizations`
......
...@@ -43,7 +43,7 @@ Depending on your needs, Next.js allows you to choose your data fetching strateg ...@@ -43,7 +43,7 @@ Depending on your needs, Next.js allows you to choose your data fetching strateg
### 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 a large impact on an application’s performance. Next.js includes specialized components and APIs that automatically optimize them for you. [Images](/docs/app/building-your-application/optimizing/images), [fonts](/docs/app/building-your-application/optimizing/fonts), and [third-party scripts](/docs/app/guides/scripts) often have a large impact on an application’s performance. Next.js includes specialized components and APIs that automatically optimize them for you.
## Migration Steps ## Migration Steps
...@@ -575,7 +575,7 @@ If everything worked, you now have a functioning Next.js application running as ...@@ -575,7 +575,7 @@ If everything worked, you now have a functioning Next.js application running as
- [React Server Components](/docs/app/building-your-application/rendering/server-components) - [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 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 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) - **Optimize third-party scripts** with the [`<Script>` component](/docs/app/guides/scripts)
- **Enable ESLint** with Next.js recommended rules by running `npx next lint` and configuring it to match your project’s needs - **Enable ESLint** with Next.js recommended rules by running `npx next lint` and configuring it to match your project’s needs
> **Note**: Using a static export (`output: 'export'`) [does not currently support](https://github.com/vercel/next.js/issues/54393) the `useParams` hook or other server features. To use all Next.js features, remove `output: 'export'` from your `next.config.ts`. > **Note**: Using a static export (`output: 'export'`) [does not currently support](https://github.com/vercel/next.js/issues/54393) the `useParams` hook or other server features. To use all Next.js features, remove `output: 'export'` from your `next.config.ts`.
...@@ -43,7 +43,7 @@ Depending on your needs, Next.js allows you to choose your data fetching strateg ...@@ -43,7 +43,7 @@ Depending on your needs, Next.js allows you to choose your data fetching strateg
### 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. [Images](/docs/app/building-your-application/optimizing/images), [fonts](/docs/app/building-your-application/optimizing/fonts), and [third-party scripts](/docs/app/guides/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
...@@ -598,5 +598,5 @@ do next: ...@@ -598,5 +598,5 @@ do next:
- [React Server Components](/docs/app/building-your-application/rendering/server-components) - [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 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 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) - [Optimize third-party scripts with the `<Script>` component](/docs/app/guides/scripts)
- [Update your ESLint configuration to support Next.js rules](/docs/app/api-reference/config/eslint) - [Update your ESLint configuration to support Next.js rules](/docs/app/api-reference/config/eslint)
--- ---
title: OpenTelemetry title: How to set up instrumentation with OpenTelemetry
nav_title: OpenTelemetry
description: Learn how to instrument your Next.js app with OpenTelemetry. description: Learn how to instrument your Next.js app with OpenTelemetry.
--- ---
...@@ -16,7 +17,11 @@ Read [Official OpenTelemetry docs](https://opentelemetry.io/docs/) for more info ...@@ -16,7 +17,11 @@ Read [Official OpenTelemetry docs](https://opentelemetry.io/docs/) for more info
This documentation uses terms like _Span_, _Trace_ or _Exporter_ throughout this doc, all of which can be found in [the OpenTelemetry Observability Primer](https://opentelemetry.io/docs/concepts/observability-primer/). This documentation uses terms like _Span_, _Trace_ or _Exporter_ throughout this doc, all of which can be found in [the OpenTelemetry Observability Primer](https://opentelemetry.io/docs/concepts/observability-primer/).
Next.js supports OpenTelemetry instrumentation out of the box, which means that we already instrumented Next.js itself. Next.js supports OpenTelemetry instrumentation out of the box, which means that we already instrumented Next.js itself.
When you enable OpenTelemetry we will automatically wrap all your code like `getStaticProps` in _spans_ with helpful attributes.
<PagesOnly>
When you enable OpenTelemetry we will automatically wrap all your code like
`getStaticProps` in _spans_ with helpful attributes.
</PagesOnly>
## Getting Started ## Getting Started
...@@ -33,13 +38,13 @@ npm install @vercel/otel @opentelemetry/sdk-logs @opentelemetry/api-logs @opente ...@@ -33,13 +38,13 @@ npm install @vercel/otel @opentelemetry/sdk-logs @opentelemetry/api-logs @opente
<AppOnly> <AppOnly>
Next, create a custom [`instrumentation.ts`](/docs/app/building-your-application/optimizing/instrumentation) (or `.js`) file in the **root directory** of the project (or inside `src` folder if using one): Next, create a custom [`instrumentation.ts`](/docs/app/guides/instrumentation) (or `.js`) file in the **root directory** of the project (or inside `src` folder if using one):
</AppOnly> </AppOnly>
<PagesOnly> <PagesOnly>
Next, create a custom [`instrumentation.ts`](/docs/pages/building-your-application/optimizing/instrumentation) (or `.js`) file in the **root directory** of the project (or inside `src` folder if using one): Next, create a custom [`instrumentation.ts`](/docs/pages/guides/instrumentation) (or `.js`) file in the **root directory** of the project (or inside `src` folder if using one):
</PagesOnly> </PagesOnly>
......
--- ---
title: Optimizing Package Bundling title: How to optimize package bundling
nav_title: Package Bundling nav_title: Package Bundling
description: Learn how to optimize your application's server and client bundles. description: Learn how to optimize your application's server and client bundles.
related: related:
...@@ -12,7 +12,7 @@ Bundling external packages can significantly improve the performance of your app ...@@ -12,7 +12,7 @@ Bundling external packages can significantly improve the performance of your app
## Analyzing JavaScript bundles ## Analyzing JavaScript bundles
[`@next/bundle-analyzer`](https://www.npmjs.com/package/@next/bundle-analyzer) is a plugin for Next.js that helps you manage the size of your application bundles. It generates a visual report of the size of each package and their dependencies. You can use the information to remove large dependencies, split, or [lazy-load](/docs/app/building-your-application/optimizing/lazy-loading) your code. [`@next/bundle-analyzer`](https://www.npmjs.com/package/@next/bundle-analyzer) is a plugin for Next.js that helps you manage the size of your application bundles. It generates a visual report of the size of each package and their dependencies. You can use the information to remove large dependencies, split, or [lazy-load](/docs/app/guides/lazy-loading) your code.
### Installation ### Installation
......
...@@ -15,7 +15,7 @@ These Next.js optimizations are enabled by default and require no configuration: ...@@ -15,7 +15,7 @@ These Next.js optimizations are enabled by default and require no configuration:
<AppOnly> <AppOnly>
- **[Server Components](/docs/app/building-your-application/rendering/server-components):** Next.js uses Server Components by default. Server Components run on the server, and don't require JavaScript to render on the client. As such, they have no impact on the size of your client-side JavaScript bundles. You can then use [Client Components](/docs/app/building-your-application/rendering/client-components) as needed for interactivity. - **[Server Components](/docs/app/building-your-application/rendering/server-components):** Next.js uses Server Components by default. Server Components run on the server, and don't require JavaScript to render on the client. As such, they have no impact on the size of your client-side JavaScript bundles. You can then use [Client Components](/docs/app/building-your-application/rendering/client-components) as needed for interactivity.
- **[Code-splitting](/docs/app/building-your-application/routing/linking-and-navigating#how-routing-and-navigation-works):** Server Components enable automatic code-splitting by route segments. You may also consider [lazy loading](/docs/app/building-your-application/optimizing/lazy-loading) Client Components and third-party libraries, where appropriate. - **[Code-splitting](/docs/app/building-your-application/routing/linking-and-navigating#how-routing-and-navigation-works):** Server Components enable automatic code-splitting by route segments. You may also consider [lazy loading](/docs/app/guides/lazy-loading) Client Components and third-party libraries, where appropriate.
- **[Prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching):** 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. - **[Prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching):** 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.
- **[Static Rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default):** Next.js statically renders Server and Client Components on the server at build time and caches the rendered result to improve your application's performance. You can opt into [Dynamic Rendering](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) for specific routes, where appropriate. {/* TODO: Update when PPR is stable */} - **[Static Rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default):** Next.js statically renders Server and Client Components on the server at build time and caches the rendered result to improve your application's performance. You can opt into [Dynamic Rendering](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) for specific routes, where appropriate. {/* TODO: Update when PPR is stable */}
- **[Caching](/docs/app/building-your-application/caching):** Next.js caches data requests, the rendered result of Server and Client Components, static assets, and more, to reduce the number of network requests to your server, database, and backend services. You may opt out of caching, where appropriate. - **[Caching](/docs/app/building-your-application/caching):** Next.js caches data requests, the rendered result of Server and Client Components, static assets, and more, to reduce the number of network requests to your server, database, and backend services. You may opt out of caching, where appropriate.
...@@ -24,7 +24,7 @@ These Next.js optimizations are enabled by default and require no configuration: ...@@ -24,7 +24,7 @@ These Next.js optimizations are enabled by default and require no configuration:
<PagesOnly> <PagesOnly>
- **[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. - **[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/guides/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. - **[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. - **[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.
...@@ -89,7 +89,7 @@ While building your application, we recommend using the following features to en ...@@ -89,7 +89,7 @@ While building your application, we recommend using the following features to en
- **[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). - **[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. - **[`<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.
- **[`<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. - **[`<Script>` Component](/docs/app/guides/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. - **[ESLint](/docs/architecture/accessibility#linting):** Use the built-in `eslint-plugin-jsx-a11y` plugin to catch accessibility issues early.
### Security ### Security
...@@ -140,7 +140,7 @@ Before going to production, you can run `next build` to build your application l ...@@ -140,7 +140,7 @@ Before going to production, you can run `next build` to build your application l
### Analyzing bundles ### Analyzing bundles
Use the [`@next/bundle-analyzer` plugin](/docs/app/building-your-application/optimizing/package-bundling#analyzing-javascript-bundles) to analyze the size of your JavaScript bundles and identify large modules and dependencies that might be impacting your application's performance. Use the [`@next/bundle-analyzer` plugin](/docs/app/guides/package-bundling#analyzing-javascript-bundles) 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 help you understand the impact of adding new dependencies to your application: Additionally, the following tools can help you understand the impact of adding new dependencies to your application:
......
--- ---
title: Script Optimization title: How to load and optimize scripts
nav_title: Scripts nav_title: Scripts
description: Optimize 3rd party scripts with the built-in Script component. description: Optimize 3rd party scripts with the built-in Script component.
related: related:
......
...@@ -127,7 +127,7 @@ This allows you to use a singular Docker image that can be promoted through mult ...@@ -127,7 +127,7 @@ This allows you to use a singular Docker image that can be promoted through mult
> **Good to know:** > **Good to know:**
> >
> - You can run code on server startup using the [`register` function](/docs/app/building-your-application/optimizing/instrumentation). > - You can run code on server startup using the [`register` function](/docs/app/guides/instrumentation).
> - We do not recommend using the [runtimeConfig](/docs/pages/api-reference/config/next-config-js/runtime-configuration) option, as this does not work with the standalone output mode. Instead, we recommend [incrementally adopting](/docs/app/guides/migrating/app-router-migration) the App Router. > - We do not recommend using the [runtimeConfig](/docs/pages/api-reference/config/next-config-js/runtime-configuration) option, as this does not work with the standalone output mode. Instead, we recommend [incrementally adopting](/docs/app/guides/migrating/app-router-migration) the App Router.
### Caching and ISR ### Caching and ISR
......
...@@ -281,7 +281,7 @@ Learn more in the [React Query documentation](https://tanstack.com/query/latest/ ...@@ -281,7 +281,7 @@ Learn more in the [React Query documentation](https://tanstack.com/query/latest/
### Rendering components only in the browser ### Rendering components only in the browser
Client components are [prerendered](https://github.com/reactwg/server-components/discussions/4) during `next build`. If you want to disable prerendering for a Client Component and only load it in the browser environment, you can use [`next/dynamic`](/docs/app/building-your-application/optimizing/lazy-loading#nextdynamic): Client components are [prerendered](https://github.com/reactwg/server-components/discussions/4) during `next build`. If you want to disable prerendering for a Client Component and only load it in the browser environment, you can use [`next/dynamic`](/docs/app/guides/lazy-loading#nextdynamic):
```jsx ```jsx
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
......
...@@ -157,7 +157,7 @@ The majority of core Next.js features needed to build a static site are supporte ...@@ -157,7 +157,7 @@ The majority of core Next.js features needed to build a static site are supporte
- [Dynamic Routes when using `getStaticPaths`](/docs/app/building-your-application/routing/dynamic-routes) - [Dynamic Routes when using `getStaticPaths`](/docs/app/building-your-application/routing/dynamic-routes)
- Prefetching with `next/link` - Prefetching with `next/link`
- Preloading JavaScript - Preloading JavaScript
- [Dynamic Imports](/docs/pages/building-your-application/optimizing/lazy-loading) - [Dynamic Imports](/docs/pages/guides/lazy-loading)
- Any styling options (e.g. CSS Modules, styled-jsx) - Any styling options (e.g. CSS Modules, styled-jsx)
- [Client-side data fetching](/docs/pages/building-your-application/data-fetching/client-side) - [Client-side data fetching](/docs/pages/building-your-application/data-fetching/client-side)
- [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) - [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props)
......
--- ---
title: Third Party Libraries title: How to optimize third-party libraries
nav_title: Third Party Libraries
description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package. description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package.
--- ---
......
--- ---
title: Video Optimization title: How to use and optimize videos
nav_title: Videos nav_title: Videos
description: Recommendations and best practices for optimizing videos in your Next.js application. description: Recommendations and best practices for optimizing videos in your Next.js application.
--- ---
......
...@@ -43,4 +43,4 @@ Next.js `/public` folder can be used to serve static assets like images, fonts, ...@@ -43,4 +43,4 @@ Next.js `/public` folder can be used to serve static assets like images, fonts,
## Analytics and Monitoring ## Analytics and Monitoring
For large applications, Next.js integrates with popular analytics and monitoring tools to help you understand how your application is performing. Learn more in the <PagesOnly>[Analytics](/docs/app/building-your-application/optimizing/analytics), </PagesOnly> [OpenTelemetry](/docs/pages/building-your-application/optimizing/open-telemetry)<PagesOnly>,</PagesOnly> and [Instrumentation](/docs/pages/building-your-application/optimizing/instrumentation) guides. For large applications, Next.js integrates with popular analytics and monitoring tools to help you understand how your application is performing. Learn more in the <PagesOnly>[Analytics](/docs/app/guides/analytics), </PagesOnly> [OpenTelemetry](/docs/pages/guides/open-telemetry)<PagesOnly>,</PagesOnly> and [Instrumentation](/docs/pages/guides/instrumentation) guides.
...@@ -5,7 +5,7 @@ description: Optimize third-party scripts in your Next.js application using the ...@@ -5,7 +5,7 @@ description: Optimize third-party scripts in your Next.js application using the
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
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. 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/guides/scripts) page.
```tsx filename="app/dashboard/page.tsx" switcher ```tsx filename="app/dashboard/page.tsx" switcher
import Script from 'next/script' import Script from 'next/script'
......
...@@ -9,7 +9,7 @@ To use it, place the file in the **root** of your application or inside a `src` ...@@ -9,7 +9,7 @@ To use it, place the file in the **root** of your application or inside a `src`
## Usage ## Usage
Unlike [server-side instrumentation](/docs/app/building-your-application/optimizing/instrumentation), you do not need to export any specific functions. You can write your monitoring code directly in the file: Unlike [server-side instrumentation](/docs/app/guides/instrumentation), you do not need to export any specific functions. You can write your monitoring code directly in the file:
```ts filename="instrumentation-client.ts" switcher ```ts filename="instrumentation-client.ts" switcher
// Set up performance monitoring // Set up performance monitoring
......
...@@ -4,7 +4,7 @@ description: API reference for the instrumentation.js file. ...@@ -4,7 +4,7 @@ description: API reference for the instrumentation.js file.
related: related:
title: Learn more about Instrumentation title: Learn more about Instrumentation
links: links:
- app/building-your-application/optimizing/instrumentation - app/guides/instrumentation
--- ---
The `instrumentation.js|ts` file is used to integrate observability tools into your application, allowing you to track the performance and behavior, and to debug issues in production. The `instrumentation.js|ts` file is used to integrate observability tools into your application, allowing you to track the performance and behavior, and to debug issues in production.
......
...@@ -1047,7 +1047,7 @@ The following metadata types do not currently have built-in support. However, th ...@@ -1047,7 +1047,7 @@ The following metadata types do not currently have built-in support. However, th
| `<base>` | Render the tag in the layout or page itself. | | `<base>` | Render the tag in the layout or page itself. |
| `<noscript>` | Render the tag in the layout or page itself. | | `<noscript>` | Render the tag in the layout or page itself. |
| `<style>` | Learn more about [styling in Next.js](/docs/app/building-your-application/styling/css). | | `<style>` | Learn more about [styling in Next.js](/docs/app/building-your-application/styling/css). |
| `<script>` | Learn more about [using scripts](/docs/app/building-your-application/optimizing/scripts). | | `<script>` | Learn more about [using scripts](/docs/app/guides/scripts). |
| `<link rel="stylesheet" />` | `import` stylesheets directly in the layout or page itself. | | `<link rel="stylesheet" />` | `import` stylesheets directly in the layout or page itself. |
| `<link rel="preload />` | Use [ReactDOM preload method](#link-relpreload) | | `<link rel="preload />` | Use [ReactDOM preload method](#link-relpreload) |
| `<link rel="preconnect" />` | Use [ReactDOM preconnect method](#link-relpreconnect) | | `<link rel="preconnect" />` | Use [ReactDOM preconnect method](#link-relpreconnect) |
......
...@@ -5,7 +5,7 @@ description: Use the `crossOrigin` option to add a crossOrigin tag on the `scrip ...@@ -5,7 +5,7 @@ description: Use the `crossOrigin` option to add a crossOrigin tag on the `scrip
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
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 <AppOnly>[`next/script`](/docs/app/building-your-application/optimizing/scripts) component</AppOnly> <PagesOnly>[`next/script`](/docs/pages/building-your-application/optimizing/scripts) and [`next/head`](/docs/pages/api-reference/components/head)components</PagesOnly>, and define how cross-origin requests should be handled. 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 <AppOnly>[`next/script`](/docs/app/guides/scripts) component</AppOnly> <PagesOnly>[`next/script`](/docs/pages/guides/scripts) and [`next/head`](/docs/pages/api-reference/components/head)components</PagesOnly>, and define how cross-origin requests should be handled.
```js filename="next.config.js" ```js filename="next.config.js"
module.exports = { module.exports = {
......
...@@ -35,7 +35,7 @@ module.exports = { ...@@ -35,7 +35,7 @@ module.exports = {
Changing these values affects _all_ Next.js pages, including the following: Changing these values affects _all_ Next.js pages, including the following:
- [`middleware.js`](/docs/pages/building-your-application/routing/middleware) - [`middleware.js`](/docs/pages/building-your-application/routing/middleware)
- [`instrumentation.js`](/docs/pages/building-your-application/optimizing/instrumentation) - [`instrumentation.js`](/docs/pages/guides/instrumentation)
- `pages/_document.js` - `pages/_document.js`
- `pages/_app.js` - `pages/_app.js`
- `pages/api/` - `pages/api/`
......
--- ---
title: Analytics title: How to set up analytics
description: Measure and track page performance using Next.js Speed Insights nav_title: Analytics
source: app/building-your-application/optimizing/analytics description: Measure and track page performance using Next.js
source: app/guides/analytics
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
--- ---
title: Instrumentation title: How to set up instrumentation
nav_title: Instrumentation
description: Learn how to use instrumentation to run code at server startup in your Next.js app description: Learn how to use instrumentation to run code at server startup in your Next.js app
source: app/building-your-application/optimizing/instrumentation source: app/guides/instrumentation
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
--- ---
title: Lazy Loading title: How to lazy load Client Components and libraries
nav_title: Lazy Loading
description: Lazy load imported libraries and React Components to improve your application's overall loading performance. description: Lazy load imported libraries and React Components to improve your application's overall loading performance.
source: app/building-your-application/optimizing/lazy-loading source: app/guides/lazy-loading
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
--- ---
title: OpenTelemetry title: How to instrument your Next.js app with OpenTelemetry
nav_title: OpenTelemetry
description: Learn how to instrument your Next.js app with OpenTelemetry. description: Learn how to instrument your Next.js app with OpenTelemetry.
source: app/building-your-application/optimizing/open-telemetry source: app/guides/open-telemetry
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
--- ---
title: Optimizing Bundling title: How to optimize package bundling
nav_title: Bundling nav_title: Package Bundling
description: Learn how to optimize your application's server and client bundles. description: Learn how to optimize your application's server and client bundles.
source: app/building-your-application/optimizing/package-bundling source: app/guides/package-bundling
related: related:
description: Learn more about optimizing your application for production. description: Learn more about optimizing your application for production.
links: links:
......
--- ---
title: Script Optimization title: How to load and optimize scripts
nav_title: Scripts nav_title: Scripts
description: Optimize 3rd party scripts with the built-in Script component. description: Optimize 3rd party scripts with the built-in Script component.
source: app/building-your-application/optimizing/scripts source: app/guides/scripts
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
--- ---
title: Third Party Libraries title: How to optimize third-party libraries
nav_title: Third Party Libraries
description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package. description: Optimize the performance of third-party libraries in your application with the `@next/third-parties` package.
source: app/building-your-application/optimizing/third-party-libraries source: app/guides/third-party-libraries
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
...@@ -60,7 +60,7 @@ or wrapped into maximum one level of `<React.Fragment>` or arrays—otherwise th ...@@ -60,7 +60,7 @@ or wrapped into maximum one level of `<React.Fragment>` or arrays—otherwise th
## Use `next/script` for scripts ## Use `next/script` 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`. We recommend using [`next/script`](/docs/pages/guides/scripts) in your component instead of manually creating a `<script>` in `next/head`.
## No `html` or `body` tags ## No `html` or `body` tags
......
...@@ -6,7 +6,7 @@ description: Add client and server runtime configuration to your Next.js app. ...@@ -6,7 +6,7 @@ description: Add client and server runtime configuration to your Next.js app.
> **Warning:** > **Warning:**
> >
> - **This feature is deprecated.** We recommend using [environment variables](/docs/pages/guides/environment-variables) instead, which also can support reading runtime values. > - **This feature is deprecated.** We recommend using [environment variables](/docs/pages/guides/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). > - You can run code on server startup using the [`register` function](/docs/app/guides/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/config/next-config-js/output#automatically-copying-traced-files), or [React Server Components](/docs/app/building-your-application/rendering/server-components). > - 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/config/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: To add runtime configuration to your app, open `next.config.js` and add the `publicRuntimeConfig` and `serverRuntimeConfig` configs:
......
...@@ -27,4 +27,4 @@ export default function App({ Component, pageProps }) { ...@@ -27,4 +27,4 @@ export default function App({ Component, pageProps }) {
## Useful links ## Useful links
- [Docs for Next.js Script component](/docs/pages/building-your-application/optimizing/scripts) - [Docs for Next.js Script component](/docs/pages/guides/scripts)
...@@ -30,4 +30,4 @@ const DynamicComponent = dynamic(() => import('../components/hello'), { ...@@ -30,4 +30,4 @@ const DynamicComponent = dynamic(() => import('../components/hello'), {
## Useful Links ## Useful Links
- [Dynamic Import](/docs/pages/building-your-application/optimizing/lazy-loading) - [Dynamic Import](/docs/pages/guides/lazy-loading)
...@@ -30,4 +30,4 @@ You should remove `loading` from `next/dynamic` usages, and use `<Suspense />`'s ...@@ -30,4 +30,4 @@ You should remove `loading` from `next/dynamic` usages, and use `<Suspense />`'s
## Useful Links ## Useful Links
- [Dynamic Import Suspense Usage](/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) - [Dynamic Import Suspense Usage](/docs/pages/guides/lazy-loading#nextdynamic)
...@@ -37,4 +37,4 @@ Look for any usage of the `next/script` component and make sure that `src` is pr ...@@ -37,4 +37,4 @@ Look for any usage of the `next/script` component and make sure that `src` is pr
## Useful Links ## Useful Links
- [Script Component in Documentation](/docs/pages/building-your-application/optimizing/scripts) - [Script Component in Documentation](/docs/pages/guides/scripts)
...@@ -65,11 +65,11 @@ export default function Page() { ...@@ -65,11 +65,11 @@ export default function Page() {
> **Good to know:** > **Good to know:**
> >
> - If you are using the Pages Router, please refer to the [`pages/` documentation](/docs/pages/building-your-application/optimizing/third-party-libraries). > - If you are using the Pages Router, please refer to the [`pages/` documentation](/docs/pages/guides/third-party-libraries).
> - `@next/third-parties` also supports [Google Tag Manager](/docs/app/building-your-application/optimizing/third-party-libraries#google-tag-manager) and other third parties. > - `@next/third-parties` also supports [Google Tag Manager](/docs/app/guides/third-party-libraries#google-tag-manager) and other third parties.
> - Using `@next/third-parties` is not required. You can also use the `next/script` component directly. Refer to the [`next/script` documentation](/docs/app/building-your-application/optimizing/scripts) to learn more. > - Using `@next/third-parties` is not required. You can also use the `next/script` component directly. Refer to the [`next/script` documentation](/docs/app/guides/scripts) to learn more.
## Useful Links ## Useful Links
- [`@next/third-parties` Documentation](/docs/app/building-your-application/optimizing/third-party-libraries) - [`@next/third-parties` Documentation](/docs/app/guides/third-party-libraries)
- [`next/script` Documentation](/docs/app/building-your-application/optimizing/scripts) - [`next/script` Documentation](/docs/app/guides/scripts)
...@@ -57,5 +57,5 @@ export default function Document() { ...@@ -57,5 +57,5 @@ export default function Document() {
## Useful Links ## Useful Links
- [App Router Script Optimization](/docs/app/building-your-application/optimizing/scripts) - [App Router Script Optimization](/docs/app/guides/scripts)
- [Pages Router Script Optimization](/docs/pages/building-your-application/optimizing/scripts) - [Pages Router Script Optimization](/docs/pages/guides/scripts)
...@@ -49,4 +49,4 @@ export default function Index() { ...@@ -49,4 +49,4 @@ export default function Index() {
## Useful Links ## Useful Links
- [next/head](/docs/pages/api-reference/components/head) - [next/head](/docs/pages/api-reference/components/head)
- [next/script](/docs/pages/building-your-application/optimizing/scripts) - [next/script](/docs/pages/guides/scripts)
...@@ -32,4 +32,4 @@ export default MyApp ...@@ -32,4 +32,4 @@ export default MyApp
## Useful Links ## Useful Links
- [custom-app](/docs/pages/building-your-application/routing/custom-app) - [custom-app](/docs/pages/building-your-application/routing/custom-app)
- [next-script](/docs/pages/building-your-application/optimizing/scripts) - [next-script](/docs/pages/guides/scripts)
...@@ -28,5 +28,5 @@ export default function Dashboard() { ...@@ -28,5 +28,5 @@ export default function Dashboard() {
## Useful Links ## Useful Links
- [Optimizing Scripts](/docs/pages/building-your-application/optimizing/scripts) - [Optimizing Scripts](/docs/pages/guides/scripts)
- [`next/script` API Reference](/docs/pages/api-reference/components/script) - [`next/script` API Reference](/docs/pages/api-reference/components/script)
...@@ -51,7 +51,7 @@ During React hydration, `useEffect` is called. This means browser APIs like `win ...@@ -51,7 +51,7 @@ During React hydration, `useEffect` is called. This means browser APIs like `win
### Solution 2: Disabling SSR on specific components ### Solution 2: Disabling SSR on specific components
Next.js allows you to [disable prerendering](/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr) on specific components, which can prevent hydration mismatches. Next.js allows you to [disable prerendering](/docs/app/guides/lazy-loading#skipping-ssr) on specific components, which can prevent hydration mismatches.
```jsx ```jsx
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment