コンテンツにスキップ

noBeforeInteractiveScriptOutsideDocument

このコンテンツはまだ日本語訳がありません。

biome.json
{
"linter": {
"rules": {
"nursery": {
"noBeforeInteractiveScriptOutsideDocument": "error"
}
}
}
}

Prevent usage of next/script’s beforeInteractive strategy outside of pages/_document.js in a Next.js project.

Next.js provides a next/script component to optimize the loading of third-party scripts. Using the beforeInteractive strategy allows scripts to be preloaded before any first-party code. beforeInteractive scripts must be placed in pages/_document.js.

This rule checks for any usage of the beforeInteractive scripts outside of these files.

pages/index.jsx
import Script from 'next/script'
export default function Index() {
return (
<div>
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
></Script>
</div>
)
}
code-block.jsx:7:7 lint/nursery/noBeforeInteractiveScriptOutsideDocument ━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use next/script component with the `beforeInteractive` strategy outside of pages/_document.js.

5 │ return (
6 │ <div>
> 7 │ <Script
^^^^^^^
> 8 │ src=“https://example.com/script.js
> 9 │ strategy=“beforeInteractive”
> 10 │ ></Script>
^
11 │ </div>
12 │ )

See the Next.js docs for more details.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

pages/_document.jsx
import { Html, Head, Main, NextScript } from 'next/document'
import Script from 'next/script'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
></Script>
</body>
</Html>
)
}