Unverified Commit 72743bce authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Update next/script docs to clear up confusion around next/head and client-side JS (#26253)

parent 4f3674cc
......@@ -6,23 +6,41 @@ description: Next.js helps you optimize loading third-party scripts with the bui
Since version **11**, Next.js has a built-in Script component.
Example of usage
Example of usage:
```js
import Script from 'next/script'
// Before
<script
async
src="https://www.google-analytics.com/analytics.js"
/>
// pages/index.js
import Head from 'next/head'
function Home() {
return (
<>
<Head>
<script async src="https://www.google-analytics.com/analytics.js" />
</Head>
</Head>
)
}
// After
<Script
src="https://www.google-analytics.com/analytics.js"
/>
// pages/index.js
function Home() {
return (
<>
<Script src="https://www.google-analytics.com/analytics.js" />
</>
)
}
```
> Note: `next/script` should **not** be wrapped in `next/head`.
> Note: `next/script` should **not** be used in `pages/_document.js` as `next/script` has client-side functionality to ensure loading order.
Three loading strategies will be initially supported for wrapping third-party scripts:
- `beforeInteractive`
......
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