Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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