Performance: Script component for third-party scripts
HIGH IMPACT
This affects page load speed and interaction responsiveness by controlling when and how third-party scripts load and execute.
import Script from 'next/script'; export default function Page() { return ( <> <Script src="https://example.com/analytics.js" strategy="lazyOnload" /> <main>Main content here</main> </> ); }
export default function Page() { return ( <> <script src="https://example.com/analytics.js"></script> <main>Main content here</main> </> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Raw <script> tag in JSX | Minimal DOM nodes | Blocks HTML parsing causing multiple reflows | High paint cost due to delayed content | [X] Bad |
| Next.js Script with strategy='lazyOnload' | Minimal DOM nodes | Single reflow after main content | Low paint cost, fast content display | [OK] Good |