2023-07-05 15:11:16 +02:00
|
|
|
---
|
|
|
|
title: No Sync Scripts
|
|
|
|
---
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
> Prevent synchronous scripts.
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Why This Error Occurred
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
A synchronous script was used which can impact your webpage performance.
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Possible Ways to Fix It
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
#### Script component (recommended)
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
```jsx filename="pages/index.js"
|
2021-06-17 10:19:26 +02:00
|
|
|
import Script from 'next/script'
|
2021-04-30 13:09:07 +02:00
|
|
|
|
2022-02-04 16:18:35 +01:00
|
|
|
function Home() {
|
2021-04-30 13:09:07 +02:00
|
|
|
return (
|
|
|
|
<div class="container">
|
2021-05-13 12:08:07 +02:00
|
|
|
<Script src="https://third-party-script.js"></Script>
|
2021-04-30 13:09:07 +02:00
|
|
|
<div>Home Page</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|
|
|
|
```
|
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
#### Use `async` or `defer`
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script src="https://third-party-script.js" async />
|
|
|
|
<script src="https://third-party-script.js" defer />
|
|
|
|
```
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Useful Links
|
2021-04-30 13:09:07 +02:00
|
|
|
|
|
|
|
- [Efficiently load third-party JavaScript](https://web.dev/efficiently-load-third-party-javascript/)
|