Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
72743bce
Unverified
Commit
72743bce
authored
Jun 17, 2021
by
Tim Neutkens
Committed by
GitHub
Jun 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update next/script docs to clear up confusion around next/head and client-side JS (#26253)
parent
4f3674cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
10 deletions
+28
-10
script.md
docs/basic-features/script.md
+28
-10
No files found.
docs/basic-features/script.md
View file @
72743bce
...
@@ -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`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment