--- description: Next.js helps you optimize loading third-party scripts with the built-in next/script component. --- # Script Component
Version History | Version | Changes | | --------- | ------------------------- | | `v11.0.0` | `next/script` introduced. |
The Next.js Script component enables developers to set the loading priority of third-party scripts to save developer time and improve loading performance. Websites often need third parties for things like analytics, ads, customer support widgets, and consent management. However, these scripts tend to be heavy on loading performance and can drag down the user experience. Developers often struggle to decide where to place them in an application for optimal loading. With `next/script`, you can define the `strategy` property and Next.js will optimize loading for the script: - `beforeInteractive`: For critical scripts that need to be fetched and executed **before** the page is interactive, such as bot detection and consent management. These scripts are injected into the initial HTML from the server and run before self-bundled JavaScript is executed. - `afterInteractive` (**default**): For scripts that can fetch and execute **after** the page is interactive, such as tag managers and analytics. These scripts are injected on the client-side and will run after hydration. - `lazyOnload` For scripts that can wait to load during idle time, such as chat support and social media widgets. > **Note:** > > - ` // or