Unverified Commit e7e567b1 authored by Ken aka Frosty's avatar Ken aka Frosty Committed by GitHub

[docs] Functional syntax for _document example in Basic Features: Font Optimization (#40140)



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent abddee74
...@@ -27,28 +27,24 @@ To add a web font to your Next.js application, add the font to a [Custom `Docume ...@@ -27,28 +27,24 @@ To add a web font to your Next.js application, add the font to a [Custom `Docume
```js ```js
// pages/_document.js // pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document' import { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document { export default function Document() {
render() { return (
return ( <Html>
<Html> <Head>
<Head> <link
<link href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
href="https://fonts.googleapis.com/css2?family=Inter&display=optional" rel="stylesheet"
rel="stylesheet" />
/> </Head>
</Head> <body>
<body> <Main />
<Main /> <NextScript />
<NextScript /> </body>
</body> </Html>
</Html> )
)
}
} }
export default MyDocument
``` ```
Adding fonts to `_document` is preferred over individual pages. When adding fonts to a single page with [`next/head`](/docs/api-reference/next/head.md), font optimizations included by Next.js will not work on navigations between pages client-side or when using [streaming](/docs/advanced-features/react-18/streaming.md). Adding fonts to `_document` is preferred over individual pages. When adding fonts to a single page with [`next/head`](/docs/api-reference/next/head.md), font optimizations included by Next.js will not work on navigations between pages client-side or when using [streaming](/docs/advanced-features/react-18/streaming.md).
......
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