---
title: "Script loading strategy (perf/script-strategy)"
description: "beforeInteractive only works in the root layout (or pages/_document); tag managers and pixels loaded afterInteractive compete with hydration and inflate Total Blocking Time."
url: http://localhost:4173/rules/perf/script-strategy
updated: 2026-11-11
---

# Script loading strategy

> `perf/script-strategy` is a vetd rule. It flags: Script loading strategy. It runs on every `check`, together with the TypeScript check.

| Fact | Value |
| --- | --- |
| Rule id | `perf/script-strategy` |
| Severity | warning |
| Group | Performance: fonts, images, scripts and bundle |
| Tags | performance, nextjs-16, lighthouse |

## Why it matters

beforeInteractive only works in the root layout (or pages/_document); tag managers and pixels loaded afterInteractive compete with hydration and inflate Total Blocking Time.

## How to fix it

Move beforeInteractive scripts to the root layout; load analytics with @next/third-parties or strategy="lazyOnload" (or worker).

## Credit

Based on work by:

- [Next.js team](https://nextjs.org): The Script component's strategies control when third-party scripts load; beforeInteractive is reserved for the root layout.

## References

- [Script Component](https://nextjs.org/docs/app/api-reference/components/script), Next.js
- [How to load and optimize scripts](https://nextjs.org/docs/app/guides/scripts), Next.js
- [Efficiently load third-party JavaScript](https://web.dev/articles/efficiently-load-third-party-javascript), web.dev
- [Reduce the impact of third-party code](https://developer.chrome.com/docs/lighthouse/performance/third-party-summary), Chrome for Developers

## See it

Demos in the vetd Lab:

- [Load scripts with next/script](http://localhost:4173/lab/nextjs/script-loading-strategy)

## Related rules

- [`perf/sync-script`](http://localhost:4173/rules/perf/sync-script.md)

## Get this text from vetd

MCP: call `explain` with `{ "diagnosticId": "perf/script-strategy" }`. CLI: `npx vetd explain perf/script-strategy`.

---

[All 92 rules](http://localhost:4173/rules.md) · Previous: [`perf/sync-script`](http://localhost:4173/rules/perf/sync-script.md) · Next: [`perf/client-page`](http://localhost:4173/rules/perf/client-page.md)
