diff --git a/docs/basic-features/script.md b/docs/basic-features/script.md index 7acbbdb56abf7..2e8e2b658a73c 100644 --- a/docs/basic-features/script.md +++ b/docs/basic-features/script.md @@ -4,9 +4,30 @@ description: Next.js helps you optimize loading third-party scripts with the bui # Script Component -Since version **11**, Next.js has a built-in Script component. +
+ Version History -Example of usage: +| 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:** These loading strategies work the same for inline scripts wrapped with ` // or + +/> +``` -// All script attributes are forwarded to the final element -