Next.Js Example

adsense head tag doesn't support data-nscript attribute

March 16th, 2023

adsense head tag doesn't support data-nscript attribute's picture

About:

Script component results in different attributes based on the strategy

As of Next12 it looks like NextJS is adding a data attribute (data-nscript) to scripts rendered by the built in Script Tag. This behavior breaks a key third script in our application which uses data attributes for configuring to fit the developer's preference.

with code like this

<Script src="test.js" id="test" crossOrigin="anonymous" data-test="test" defer={false} strategy="beforeInteractive" />

the output is

<script src="test.js" id="test" data-test="test" defer="" data-nscript="beforeInteractive"></script>

Code like this below

<Script src="test.js" id="test" crossOrigin="anonymous" data-test="test" defer={false} strategy="afterInteractive" />

the output is

<script src="test.js" id="test" crossorigin="anonymous" data-test="test" defer="false" data-nscript="afterInteractive"></script>
Blog Post Image

Technologies Used:

README.md:

The strategy attribute when using Script component imported from "next/script" is interpreted as data-nscript attribute in the browser, so if you're trying to solve that problem or warning, just remove the strategy attribute.

Share this:

Nedx ยฉ 2023