How to add custom inline script into head element?
Answered
Eared Grebe posted this in #help-forum
Eared GrebeOP
In my project, there is a requirement of putting custom scripts, both from external source and inline script into the head element dynamically.
Script tag doesn't help because it only supports external source.
Is there a way to do that?
Script tag doesn't help because it only supports external source.
Is there a way to do that?
Answered by B33fb0n3
You can use the
When it's placed anywhere inside your app, nextjs will automatically place it at the end of your head
<Script />
tag from nextjs itself. As you said: it supports external source and you can add inline script like:<Script id="my-script">{`console.log('Hello world!');`}</Script>
When it's placed anywhere inside your app, nextjs will automatically place it at the end of your head
4 Replies
@Eared Grebe In my project, there is a requirement of putting custom scripts, both from external source and inline script into the head element dynamically.
Script tag doesn't help because it only supports external source.
Is there a way to do that?
You can use the
When it's placed anywhere inside your app, nextjs will automatically place it at the end of your head
<Script />
tag from nextjs itself. As you said: it supports external source and you can add inline script like:<Script id="my-script">{`console.log('Hello world!');`}</Script>
When it's placed anywhere inside your app, nextjs will automatically place it at the end of your head
Answer
Eared GrebeOP
Thank you. Let me try.
happy to help