Konrad
Konrad

Reputation: 7198

<Head> in _document.js or _app.js

Should I use <Head> from next/head and use it inside _app.js or should I use <Head> from next/document and use it in _document.js?

I'm kind of confused about when should I choose what. From what I understand _document.js is only rendered on the server-side and _app.js is rendered on both client-side and server-side.

Things I've learnt so far:

Does that mean I can just put everything <Head> related inside _app.js and be done with it? Or does it give any advantage to put all the other tags(except title and viewport) in _document.js?

Upvotes: 4

Views: 3834

Answers (1)

Ahmed Abdulrahman
Ahmed Abdulrahman

Reputation: 469

You can put anything related to Favicon, preloading Fonts, GTM ..etc in _document.js and Viewport meta related can be added into _app.js. For other other meta tags like robots, og, twitter, ... etc can be added in <Head> of each page in your app.

enter image description here

Upvotes: 7

Related Questions