Add script tag to <head> from within a sub route
Answered
Indian Spitz posted this in #help-forum
Indian SpitzOP
Hey guys, anyone know how to add a script tag to head with other properties than those provided by the <Script> tag from a page within a sub route like /blog/[id]?
I've looked at https://nextjs.org/docs/app/building-your-application/optimizing/scripts but I can't figure out if it's possible to add it to <head>, it only ends up in <body>.
Is it even possible?
Many thanks in advance 🙇
I've looked at https://nextjs.org/docs/app/building-your-application/optimizing/scripts but I can't figure out if it's possible to add it to <head>, it only ends up in <body>.
Is it even possible?
Many thanks in advance 🙇
Answered by Indian Spitz
Managed to solve it by adding the <Script> with strategy="beforeInteractive". It works but I get a warning which says:
I can live with it 🙂
next/script'sbeforeInteractivestrategy should not be used outside ofpages/_document.js. See: https://nextjs.org/docs/messages/no-before-interactive-script-outside-documenteslint@next/next/no-before-interactive-script-outside-document
I can live with it 🙂
<Script id="schema.org" type="application/ld+json" strategy="beforeInteractive">
{content}
</Script>1 Reply
Indian SpitzOP
Managed to solve it by adding the <Script> with strategy="beforeInteractive". It works but I get a warning which says:
I can live with it 🙂
next/script'sbeforeInteractivestrategy should not be used outside ofpages/_document.js. See: https://nextjs.org/docs/messages/no-before-interactive-script-outside-documenteslint@next/next/no-before-interactive-script-outside-document
I can live with it 🙂
<Script id="schema.org" type="application/ld+json" strategy="beforeInteractive">
{content}
</Script>Answer