beforeInteractive
A next/script strategy that loads the script before any Next.js code and before the page hydrates.
In more detail
Only use it for scripts that must run first, such as bot detection or cookie consent managers, and place it in the root layout. It delays interactivity, so keep such scripts rare.
Related terms
- next/script — The Next.js Script component, which loads third-party JavaScript with a chosen strategy so it does not block the page.
- consent manager — A script that asks visitors for permission before tracking cookies are set, as privacy laws in many regions require.
- hydration — The step where React in the browser attaches event handlers and state to HTML that was already rendered on the server.
Taught in
- Script Optimization: next/script & Lazy Third Parties — Next.js 15 & Modern App Router Architecture