-
So I noticed _document.js from Next and all the parts of html, head, and some others... When / Why do I need to use _document.js? Usually If I want something to show on every page I put it in the _app.js ... right now for example I am using next/head and next/script on the _app.js.... What is the purpose of using _document.js ? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
You can use the
For example, applying a CSS class to the body of the page, as part of the render logic, is not possible in _app. It is only possible via side-effects. And that's about it. Some often try to inject initial data, and other discouraged things in _document, which you're probably better off ignoring.
All of that because |
Beta Was this translation helpful? Give feedback.
-
Hey! you are back! Well thanks... I was asking because I want to convert a next.js app into a pwa, and some code samples were using _document while other samples were using _app .... Last week I was trying the next-pwa plugin, but didn't work to automatically generate the sw.js page and some other stuff.... I might give it another try just to get it going, but I am also gonna study pwa's in more details to get some of the features working later on as well... |
Beta Was this translation helpful? Give feedback.
-
Oh.. BTW.... can you have both? _document.js and _app.js ? |
Beta Was this translation helpful? Give feedback.
-
Sorry, did you mean to say _document? |
Beta Was this translation helpful? Give feedback.
You can use the
_document
to set lang, load fonts, load scripts before page interactivity, collect style sheets for CSS in JS solutions like Styled Components, among a few other things.For example, applying a CSS class to the body of the page, as p…