You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-features/measuring-performance.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,8 +30,8 @@ The `metric` object returned to the function consists of a number of properties:
30
30
31
31
-`id`: Unique identifier for the metric in the context of the current page load
32
32
-`name`: Metric name
33
-
-`startTime`: First recorded timestamp of the performance entry (if applicable)
34
-
-`value`: Value, or duration, of performance entry
33
+
-`startTime`: First recorded timestamp of the performance entry in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)(if applicable)
34
+
-`value`: Value, or duration in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp), of the performance entry
35
35
-`label`: Type of metric (`web-vital` or `custom`)
Copy file name to clipboardExpand all lines: docs/api-reference/next.config.js/redirects.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,3 +92,5 @@ module.exports = {
92
92
},
93
93
}
94
94
```
95
+
96
+
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. Note: to ensure IE11 compatibility a `Refresh` header is automatically added for the 308 status code.
Next.js allows you to import CSS files from a JavaScript file.
8
16
This is possible because Next.js extends the concept of [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) beyond JavaScript.
9
17
@@ -129,8 +137,8 @@ module.exports = {
129
137
130
138
To support importing `.less` or `.styl` files you can use the following plugins:
We bundle [styled-jsx](https://github.com/zeit/styled-jsx) to provide support for isolated scoped CSS.
177
+
We bundle [styled-jsx](https://github.com/vercel/styled-jsx) to provide support for isolated scoped CSS.
168
178
The aim is to support "shadow CSS" similar to Web Components, which unfortunately [do not support server-rendering and are JS-only](https://github.com/w3c/webcomponents/issues/71).
169
179
170
180
See the above examples for other popular CSS-in-JS solutions (like Styled Components).
@@ -202,7 +212,7 @@ function HelloWorld() {
202
212
exportdefaultHelloWorld
203
213
```
204
214
205
-
Please see the [styled-jsx documentation](https://github.com/zeit/styled-jsx) for more examples.
215
+
Please see the [styled-jsx documentation](https://github.com/vercel/styled-jsx) for more examples.
Copy file name to clipboardExpand all lines: docs/basic-features/data-fetching.md
+81-1Lines changed: 81 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,11 @@ The `context` parameter is an object containing the following keys:
54
54
-`preview` is `true` if the page is in the preview mode and `false` otherwise. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
55
55
-`previewData` contains the preview data set by `setPreviewData`. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
56
56
57
+
`getStaticProps` should return an object with:
58
+
59
+
-`props` - A **required** object with the props that will be received by the page component. It should be a [serializable object](https://en.wikipedia.org/wiki/Serialization)
60
+
-`revalidate` - An **optional** amount in seconds after which a page re-generation can occur. More on [Incremental Static Regeneration](#incremental-static-regeneration)
61
+
57
62
> **Note**: You can import modules in top-level scope for use in `getStaticProps`.
58
63
> Imports used in `getStaticProps` will not be bundled for the client-side, as [explained below](#write-server-side-code-directly).
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5#stable-incremental-static-regeneration) and up. If you’re using older versions of Next.js, please upgrade before trying Incremental Static Regeneration.
With [`getStaticProps`](#getstaticprops-static-generation) you don't have to stop relying in dynamic content, as **static content can also be dynamic**. Incremental Static Regeneration allows you to update _existing_ pages by re-rendering them in the background as traffic comes in.
163
+
164
+
Inspired by [stale-while-revalidate](https://tools.ietf.org/html/rfc5861), background regeneration ensures traffic is served uninterruptedly, always from static storage, and the newly built page is pushed only after it's done generating.
165
+
166
+
Consider our previous [`getStaticProps` example](#simple-example), but now with regeneration enabled:
167
+
168
+
```jsx
169
+
functionBlog({ posts }) {
170
+
return (
171
+
<ul>
172
+
{posts.map((post) => (
173
+
<li>{post.title}</li>
174
+
))}
175
+
</ul>
176
+
)
177
+
}
178
+
179
+
// This function gets called at build time on server-side.
180
+
// It may be called again, on a serverless function, if
181
+
// revalidation is enabled and a new request comes in
182
+
exportasyncfunctiongetStaticProps() {
183
+
constres=awaitfetch('https://.../posts')
184
+
constposts=awaitres.json()
185
+
186
+
return {
187
+
props: {
188
+
posts,
189
+
},
190
+
// Next.js will attempt to re-generate the page:
191
+
// - When a request comes in
192
+
// - At most once every second
193
+
revalidate:1, // In seconds
194
+
}
195
+
}
196
+
197
+
exportdefaultBlog
198
+
```
199
+
200
+
Now the list of blog posts will be revalidated once per second; if you add a new blog post it will be available almost immediately, without having to re-build your app or make a new deployment.
201
+
202
+
This works perfectly with [`fallback: true`](#fallback-true). Because now you can have a list of posts that's always up to date with the latest posts, and have a [blog post page](#fallback-pages) that generates blog posts on-demand, no matter how many posts you add or update.
203
+
204
+
#### Static content at scale
205
+
206
+
Unlike traditional SSR, [Incremental Static Regeneration](#incremental-static-regeneration) ensures you retain the benefits of static:
207
+
208
+
- No spikes in latency. Pages are served consistently fast
209
+
- Pages never go offline. If the background page re-generation fails, the old page remains unaltered
210
+
- Low database and backend load. Pages are re-computed at most once concurrently
211
+
146
212
### Reading files: Use `process.cwd()`
147
213
148
214
Files can be read directly from the filesystem in `getStaticProps`.
@@ -326,6 +392,13 @@ export default Post
326
392
327
393
#### `fallback: true`
328
394
395
+
<details>
396
+
<summary><b>Examples</b></summary>
397
+
<ul>
398
+
<li><a href="https://static-tweet.now.sh">Static generation of a large number of pages</a></li>
399
+
</ul>
400
+
</details>
401
+
329
402
If `fallback` is `true`, then the behavior of `getStaticProps` changes:
330
403
331
404
- The paths returned from `getStaticPaths` will be rendered to HTML at build time.
> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/zeit/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at.
102
+
> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/vercel/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at.
0 commit comments