Next.js Discord

Discord Forum

Questions Regarding Metadata with NextJS v13

Answered
Streak-backed Oriole posted this in #help-forum
Open in Discord
Streak-backed OrioleOP
I'm reading through the official tutorial here: https://nextjs.org/learn/basics/assets-metadata-css/third-party-javascript. It has not been updated for v13 + app directory yet, so I'm trying to follow it using the newer features.

# Question 1
They introduce this bit of JSX
<Head>
  <title>First Post</title>
</Head>

My understanding is that now you should export a Metadata object instead (either from the page, or from a layout file).
Is that correct?


# Question 2
Then, they add a bit to this (note the script tag):
<Head>
  <title>First Post</title>
  <script ... />
</Head>

Then they explain that you should use the Script component instead:
<Head>
  <title>First Post</title>
</Head>
<Script ... />

Notice how the Script component is put outside of the Head component this time around.

I'm wondering: Do I still need the Script tag for v13, or is there a new way? If so, should I put it in my page's main component, or in a layout file?
Answered by not-milo.tsx
Q1: Yes, that's correct.
Q2: You still need to use the script tag. Give a read to this page https://nextjs.org/docs/app/building-your-application/optimizing/scripts
View full answer

3 Replies

Q1: Yes, that's correct.
Q2: You still need to use the script tag. Give a read to this page https://nextjs.org/docs/app/building-your-application/optimizing/scripts
Answer
Where you put it depends on where you need it. If, for example, it's a script for analytics then it should go in the root layout
Streak-backed OrioleOP
Got it, thanks 🙂