@next/next/no-sync-scripts
Disallow <script src> without async or defer
Also called nextjs/no-sync-scripts
When the browser hits a <script> with a src, it stops reading the HTML until it has downloaded and run the file. Nothing below the tag shows up in the meantime, so a slow third-party server holds up your whole page.
With async or defer, the browser keeps reading the HTML while the file downloads. Script from next/script doesn't block either, and it lets you pick when the script loads.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"@next/next/no-sync-scripts" = "error" # or "warn"Examples#
example.jsx1 problem
export default function Checkout() {
return <scriptPrevent synchronous scripts. src="https://example.com/payments.js" />;
}example.jsxNo problems
export default function Checkout() {
return <script src="https://example.com/payments.js" defer />;
}example.jsxNo problems
import Script from "next/script";
export default function Checkout() {
return <Script src="https://example.com/payments.js" />;
}