NEXTJS_USE_NEXT_SCRIPT
Last updated March 4, 2025
Conformance is available on Enterprise plans
This rule is available from version 1.1.0.
next/script
automatically optimizes scripts for improved performance through customizable
loading strategies. By default, next/script loads scripts so that they're
non-blocking, meaning that they load after the page has loaded.
Additionally, next/script has built in event handlers for common events such
as onLoad and onError.
By default, this rule is disabled. Enable it by customizing Conformance.
For further reading, see:
- https://nextjs.org/docs/pages/building-your-application/optimizing/scripts
- https://nextjs.org/docs/pages/api-reference/components/script
This rule will catch the following code.
function insertScript() {
const script = document.createElement('script');
script.src = process.env.SCRIPT_PATH;
document.body.appendChild(script);
}function App() {
return (
<script
dangerouslySetInnerHTML={{ __html: "console.log('Hello world');" }}
/>
);
}Replace any document.createElement('script') calls and <script>
elements that are caught by this rule with next/script.
Was this helpful?