next/script
The Next.js Script component, which loads third-party JavaScript with a chosen strategy so it does not block the page.
In more detail
The strategy prop is beforeInteractive, afterInteractive (default), lazyOnload or the experimental worker. A script is loaded only once even if several pages include it.
Example
<Script src="https://example.com/widget.js" strategy="lazyOnload" />Related terms
- beforeInteractive — A next/script strategy that loads the script before any Next.js code and before the page hydrates.
- afterInteractive — The default next/script strategy, which loads the script early but after some hydration has happened.
- lazyOnload — A next/script strategy that loads the script only after everything else has loaded, during browser idle time.
- worker strategy — An experimental next/script strategy that runs a third-party script in a web worker using Partytown, keeping it off the main thread.
Taught in
- Image & Font Optimization: Zero Layout Shift Assets — Next.js 15 & Modern App Router Architecture
- Script Optimization: next/script & Lazy Third Parties — Next.js 15 & Modern App Router Architecture