# no-before-interactive-script-outside-document

Rule `nextjs/no-before-interactive-script-outside-document`. Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`.

- Source: nextjs
- Technologies: Next.js, React
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 99.7M weekly downloads of presets that enable it
- Trend: +49.8% last quarter
- Rank: #162 by reach, #829 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@next/next/no-before-interactive-script-outside-document` | yes | no | package `@next/eslint-plugin-next` | [docs](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document) |
| Oxlint | `nextjs/no-before-interactive-script-outside-document` | no | no | plugin `nextjs`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/nextjs/no-before-interactive-script-outside-document.html) |
| Biome | `correctness/noBeforeInteractiveScriptOutsideDocument` | no | no | group correctness, since 2.3.11 | [docs](https://biomejs.dev/linter/rules/no-before-interactive-script-outside-document/) |

## Code examples

### Incorrect: the rule reports this

```jsx
// pages/index.js
import Script from 'next/script'

export default function HomePage() {
  return (
    <div>
      <Script
        src="https://example.com/script.js"
        strategy="beforeInteractive"  // ❌ Wrong placement
      />
    </div>
  )
}
```

### Correct: the rule accepts this

```jsx
// pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document'
import Script from 'next/script'

class MyDocument extends Document {
  render() {
    return (
      <Html>
        <Head />
        <body>
          <Script
            src="https://example.com/script.js"
            strategy="beforeInteractive"  // ✅ Correct placement
          />
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument
```

Examples from the Oxlint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import next from "@next/eslint-plugin-next";

export default [
  {
    plugins: { "@next/next": next },
    rules: {
      "@next/next/no-before-interactive-script-outside-document": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "nextjs"
  ],
  "rules": {
    "nextjs/no-before-interactive-script-outside-document": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "correctness": {
        "noBeforeInteractiveScriptOutsideDocument": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Next.js recommended](https://lintradar.dev/presets/next-recommended.md) | ESLint | `@next/eslint-plugin-next` | 22 | 52.9M | +50.7% |
| [Next.js Core Web Vitals](https://lintradar.dev/presets/next-core-web-vitals.md) | ESLint | `eslint-config-next` | 62 | 46.8M | +48.8% |

## Related rules

- [nextjs/no-async-client-component](https://lintradar.dev/rules/nextjs/no-async-client-component.md): Prevent Client Components from being async functions.
- [nextjs/no-assign-module-variable](https://lintradar.dev/rules/nextjs/no-assign-module-variable.md): Prevent assignment to the `module` variable.
- [nextjs/next-script-for-ga](https://lintradar.dev/rules/nextjs/next-script-for-ga.md): Prefer `@next/third-parties/google` when using the inline script for Google Analytics and Tag Manager.
- [nextjs/no-css-tags](https://lintradar.dev/rules/nextjs/no-css-tags.md): Prevent manual stylesheet tags.
- [nextjs/no-duplicate-head](https://lintradar.dev/rules/nextjs/no-duplicate-head.md): Prevent duplicate usage of `<Head>` in `pages/_document.js`.
- [nextjs/no-html-link-for-pages](https://lintradar.dev/rules/nextjs/no-html-link-for-pages.md): Prevent usage of `<a>` elements to navigate to internal Next.js pages.

---

Web page: https://lintradar.dev/rules/nextjs/no-before-interactive-script-outside-document. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
