Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add "Going to production" page for App Router #59304

Merged
merged 111 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
affef87
new going to production docs page
Dec 5, 2023
6190ada
Merge branch 'canary' into docs-app-router-production-page
StephDietz Dec 5, 2023
9524d80
update caching section
Dec 5, 2023
a6c9eb7
update javascript section
Dec 5, 2023
b9ac834
error section update
Dec 5, 2023
67b2847
remove sentry section
Dec 5, 2023
3a8174e
switch order of deploying chapters
Dec 5, 2023
de1350a
update links
Dec 5, 2023
be0a117
final edits
Dec 5, 2023
2096af6
remove unused code block
Dec 5, 2023
e684b49
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
04ca7d0
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
057843b
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
f67888b
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
13471bd
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
031e69a
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
8d6546a
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
49e0434
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
d28b81e
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
d7d8422
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
b818c97
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
c65be43
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
7cb9e0c
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
cbbd380
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
2316bce
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
7f29111
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
dd5692d
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
ea54a32
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
5fb7dae
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
fcd6f43
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
2053f33
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
00426f3
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
0de09d3
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
139dd36
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
ebd0bcc
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
ee3db48
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
592b6fd
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
9a38553
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 6, 2023
6abc7fc
edits
Dec 6, 2023
4cad589
merge
Dec 6, 2023
5286c5a
clarify the server actions caching section
Dec 6, 2023
d05ec25
add two more points to recommended optimization strategies
Dec 6, 2023
7602370
update logging info
Dec 6, 2023
da50c59
update loading section
Dec 6, 2023
0f28947
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 11, 2023
18c6bbe
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 11, 2023
9ef203c
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 11, 2023
fb1506b
Merge branch 'canary' into docs-app-router-production-page
StephDietz Dec 11, 2023
b1df9a3
resolve comments left by tim
Dec 11, 2023
7cd2e99
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
807d4d1
resolve Jimmy's feedback
Dec 15, 2023
5b28da0
Merge branch 'canary' into docs-app-router-production-page
StephDietz Dec 15, 2023
6ab67f7
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
db75d6b
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
7bdcd41
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
bdd64b4
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
6d84873
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
0730e46
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
0a8afe3
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
289286f
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
9555bc7
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
b53d7cb
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
a6cf96c
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
7160f85
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
341773c
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
5e218af
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
b342835
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
15d497f
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
205b71b
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
49b4bcb
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
80ee897
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 15, 2023
7142b25
move loading section up and re-order overview bullets
Dec 15, 2023
b554b18
add parallel data fetching
Dec 15, 2023
71f7259
Merge branch 'canary' into docs-app-router-production-page
manovotny Dec 15, 2023
183d06e
Update docs/02-app/01-building-your-application/08-deploying/01-produ…
StephDietz Dec 19, 2023
5fa5e6f
fix file duplicate and link to vercel production checklist
Dec 19, 2023
dcb3241
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Dec 19, 2023
4edbbe5
Re-order pages
delbaoliveira Dec 19, 2023
a45d971
Add @next/bundle-analyzer page
delbaoliveira Dec 19, 2023
e364bad
Restructure and rewrite (wip)
delbaoliveira Dec 19, 2023
985d131
Move information to the /public folder page
delbaoliveira Dec 19, 2023
7797e5a
Tweak
delbaoliveira Dec 19, 2023
3d95618
Fix broken links
delbaoliveira Dec 19, 2023
ef097e7
Review bundle-analyzer page
delbaoliveira Dec 20, 2023
0194cf0
Review static assets page
delbaoliveira Dec 20, 2023
657160e
Add code-splitting section
delbaoliveira Dec 20, 2023
a3fb1d3
Fix broken hashes
delbaoliveira Dec 20, 2023
a423f29
Update page description
delbaoliveira Dec 20, 2023
ebac057
Fix headings
delbaoliveira Dec 20, 2023
4936fd6
Review intro
delbaoliveira Dec 20, 2023
b29dbce
Review 'automatic optimizations' section
delbaoliveira Dec 20, 2023
8a237e3
Review 'during development' section
delbaoliveira Dec 20, 2023
967038a
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Dec 21, 2023
52b0855
shipit
delbaoliveira Dec 22, 2023
0e65d69
Fix broken link
delbaoliveira Dec 22, 2023
85e60e1
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Dec 22, 2023
cdde2f7
Fix headings
delbaoliveira Dec 22, 2023
1cab334
Merge branch 'docs-app-router-production-page' of https://github.com/…
delbaoliveira Dec 22, 2023
0cd08a7
Apply suggestions from code review
delbaoliveira Dec 22, 2023
993c0bd
Apply suggestions from code review
delbaoliveira Dec 22, 2023
c9ee742
Update docs/02-app/01-building-your-application/09-deploying/01-produ…
delbaoliveira Dec 22, 2023
875ae3c
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Jan 2, 2024
b0afab4
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Jan 2, 2024
2651278
Apply Lee's feedback
delbaoliveira Jan 2, 2024
8f626d1
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Jan 2, 2024
aed9a8c
Merge pages and app
delbaoliveira Jan 3, 2024
0a84aeb
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Jan 3, 2024
56697ee
Merge branch 'canary' into docs-app-router-production-page
delbaoliveira Jan 5, 2024
790f164
Share bundle-analyzer between app and pages
delbaoliveira Jan 5, 2024
a5ca7c3
Review
delbaoliveira Jan 5, 2024
b36dea6
Use searchParams instead of useSearchParams
delbaoliveira Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This page will go through how to use `<Link>`, `useRouter()`, and dive deeper in

## `<Link>` Component

`<Link>` is a built-in component that extends the HTML `<a>` tag to provide [prefetching](#1-prefetching) and client-side navigation between routes. It is the primary way to navigate between routes in Next.js.
`<Link>` is a built-in component that extends the HTML `<a>` tag to provide [prefetching](#2-prefetching) and client-side navigation between routes. It is the primary way to navigate between routes in Next.js.

You can use it by importing it from `next/link`, and passing a `href` prop to the component:

Expand Down Expand Up @@ -185,9 +185,15 @@ For a full list of `useRouter` methods, see the [API reference](/docs/app/api-re

## How Routing and Navigation Works

The App Router uses a hybrid approach for routing and navigation. On the server, your application code is automatically code-split by route segments. And on the client, Next.js [prefetches](#1-prefetching) and [caches](#2-caching) the route segments. This means, when a user navigates to a new route, the browser doesn't reload the page, and only the route segments that change re-render - improving the navigation experience and performance.
The App Router uses a hybrid approach for routing and navigation. On the server, your application code is automatically [code-split](#1-code-splitting) by route segments. And on the client, Next.js [prefetches](#2-prefetching) and [caches](#3-caching) the route segments. This means, when a user navigates to a new route, the browser doesn't reload the page, and only the route segments that change re-render - improving the navigation experience and performance.

### 1. Prefetching
### 1. Code Splitting

Code splitting allows you to split your application code into smaller bundles to be downloaded and executed by the browser. This reduces the amount of data transferred and execution time for each request, leading to improved performance.

Server Components allow your application code to be automatically code-split by route segments. This means only the code needed for the current route is loaded on navigation.

### 2. Prefetching

Prefetching is a way to preload a route in the background before the user visits it.

Expand All @@ -209,15 +215,15 @@ See the [`<Link>` API reference](/docs/app/api-reference/components/link) for mo
>
> - Prefetching is not enabled in development, only in production.

### 2. Caching
### 3. Caching

Next.js has an **in-memory client-side cache** called the [Router Cache](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data#router-cache). As users navigate around the app, the React Server Component Payload of [prefetched](#1-prefetching) route segments and visited routes are stored in the cache.
Next.js has an **in-memory client-side cache** called the [Router Cache](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data#router-cache). As users navigate around the app, the React Server Component Payload of [prefetched](#2-prefetching) route segments and visited routes are stored in the cache.

This means on navigation, the cache is reused as much as possible, instead of making a new request to the server - improving performance by reducing the number of requests and data transferred.

Learn more about how the [Router Cache](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data) works and how to configure it.

### 3. Partial Rendering
### 4. Partial Rendering

Partial rendering means only the route segments that change on navigation re-render on the client, and any shared segments are preserved.

Expand All @@ -233,10 +239,10 @@ For example, when navigating between two sibling routes, `/dashboard/settings` a

Without partial rendering, each navigation would cause the full page to re-render on the server. Rendering only the segment that changes reduces the amount of data transferred and execution time, leading to improved performance.

### 4. Soft Navigation
### 5. Soft Navigation

Browsers perform a "hard navigation" when navigating between pages. The Next.js App Router enables "soft navigation" between pages, ensuring only the route segments that have changed are re-rendered (partial rendering). This enables client React state to be preserved during navigation.

### 5. Back and Forward Navigation
### 6. Back and Forward Navigation

By default, Next.js will maintain the scroll position for backwards and forwards navigation, and re-use route segments in the [Router Cache](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data).
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Learn about common data fetching patterns in React and Next.js.

There are a few recommended patterns and best practices for fetching data in React and Next.js. This page will go over some of the most common patterns and how to use them.

## Fetching Data on the Server
## Fetching data on the server

Whenever possible, we recommend fetching data on the server with Server Components. This allows you to:

Expand All @@ -19,7 +19,7 @@ Whenever possible, we recommend fetching data on the server with Server Componen

Then, you can mutate or update data with [Server Actions](/docs/app/building-your-application/data-fetching/server-actions-and-mutations).

## Fetching Data Where It's Needed
## Fetching data where it's needed

If you need to use the same data (e.g. current user) in multiple components in a tree, you do not have to fetch data globally, nor forward props between components. Instead, you can use `fetch` or React `cache` in the component that needs the data without worrying about the performance implications of making multiple requests for the same data.

Expand All @@ -43,7 +43,7 @@ With Server Components and [nested layouts](/docs/app/building-your-application/

To learn more about Streaming and Suspense, see the [Loading UI](/docs/app/building-your-application/routing/loading-ui-and-streaming) and [Streaming and Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense) pages.

### Parallel and Sequential Data Fetching
## Parallel and sequential data fetching

When fetching data inside React components, you need to be aware of two data fetching patterns: Parallel and Sequential.

Expand Down
4 changes: 2 additions & 2 deletions docs/02-app/01-building-your-application/04-caching/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ Next.js has an in-memory client-side cache that stores the React Server Componen
height="1375"
/>

As a user navigates between routes, Next.js caches visited route segments and [prefetches](/docs/app/building-your-application/routing/linking-and-navigating#1-prefetching) the routes the user is likely to navigate to (based on `<Link>` components in their viewport).
As a user navigates between routes, Next.js caches visited route segments and [prefetches](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching) the routes the user is likely to navigate to (based on `<Link>` components in their viewport).

This results in an improved navigation experience for the user:

- Instant backward/forward navigation because visited routes are cached and fast navigation to new routes because of prefetching and [partial rendering](/docs/app/building-your-application/routing/linking-and-navigating#3-partial-rendering).
- Instant backward/forward navigation because visited routes are cached and fast navigation to new routes because of prefetching and [partial rendering](/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering).
- No full-page reload between navigations, and React state and browser state are preserved.

> **Difference between the Router Cache and Full Route Cache**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Static Assets
title: Statics Assets in `public`
nav_title: Static Assets
description: Next.js allows you to serve static files, like images, in the public directory. You can learn how it works here.
---

Expand All @@ -17,9 +18,19 @@ export function Avatar() {
}
```

## Caching

Next.js automatically adds caching headers to immutable assets in the `public` folder. The default caching headers applied are:

```jsx
Cache-Control: public, max-age=31536000, immutable
```

## Robots, Favicons, and others

<PagesOnly>

This folder is also useful for `robots.txt`, `favicon.ico`, Google Site Verification, and any other static files (including `.html`). But make sure to not have a static file with the same name as a file in the `pages/` directory, as this will result in an error. [Read more](/docs/messages/conflicting-public-file-page).
The folder is also useful for `robots.txt`, `favicon.ico`, Google Site Verification, and any other static files (including `.html`). But make sure to not have a static file with the same name as a file in the `pages/` directory, as this will result in an error. [Read more](/docs/messages/conflicting-public-file-page).

</PagesOnly>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Bundle Analyzer
delbaoliveira marked this conversation as resolved.
Show resolved Hide resolved
description: Analyze the size of your JavaScript bundles using the @next/bundle-analyzer plugin.
related:
description: Learn more about optimizing your application for production.
links:
- app/building-your-application/deploying/production-checklist
---

[`@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 JavaScript modules. It generates a visual report of the size of each module and their dependencies. You can use the information to remove large dependencies, split your code, or only load some parts when needed, reducing the amount of data transferred to the client.

## Installation

Install the plugin by running the following command:

```bash
npm i @next/bundle-analyzers
# or
yarn add @next/bundle-analyzer
# or
pnpm i @next/bundle-analyzer
```

Then, add the bundle analyzer's settings to your `next.config.js`.

```js filename="next.config.js"
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})

/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = withBundleAnalyzer(nextConfig)
```

## Analyzing your bundles

Run the following command to analyze your bundles:

```bash
ANALYZE=true npm run build
# or
ANALYZE=true yarn build
# or
ANALYZE=true pnpm build
```

The report will open two new tab in your browser, which you can inspect. Doing this regularly while you develop and before deploying your site can help you identify large bundles earlier, and architect your application to be more performant.
Loading