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 ...@@ -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. Since version **11**, Next.js has a built-in Script component.
Example of usage Example of usage:
```js ```js
import Script from 'next/script'
// Before // Before
<script
async // pages/index.js
src="https://www.google-analytics.com/analytics.js" import Head from 'next/head'
/>
function Home() {
return (
<>
<Head>
<script async src="https://www.google-analytics.com/analytics.js" />
</Head>
</Head>
)
}
// After // 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: Three loading strategies will be initially supported for wrapping third-party scripts:
- `beforeInteractive` - `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