Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Update next/script docs to clear up confusion around next/head and cl…
Browse files Browse the repository at this point in the history
…ient-side JS (vercel#26253)
  • Loading branch information
timneutkens authored Jun 17, 2021
1 parent 799403a commit 538a528
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions docs/basic-features/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 538a528

Please sign in to comment.