---
description: Optimize your third-party scripts with the built-in `next/script` component.
---
# Optimizing Scripts
Examples
The **Script component**, [`next/script`](/docs/api-reference/next/script.md), allows you to optimally load third-party scripts anywhere in your Next.js application. It is an extension of the HTML `
```
Or by using the `dangerouslySetInnerHTML` property:
```jsx
```
> **Note**: An `id` property must be assigned for inline scripts in order for Next.js to track and optimize the script.
### Executing Additional Code
Event handlers can be used with the Script component to execute additional code after a certain event occurs:
- `onLoad`: Execute code after the script has finished loading.
- `onReady`: Execute code after the script has finished loading and every time the component is mounted.
- `onError`: Execute code if the script fails to load.
```jsx
import Script from 'next/script'
export default function Page() {
return (
<>