Skip to content

_document.js vs. _app.js -- What is the difference? Why use _document.js ? #39821

Answered by icyJoseph
Elindo586 asked this question in Help
Discussion options

You must be logged in to vote

A custom Document can update the and tags used to render a Page. This file is only rendered on the server, so event handlers like onClick cannot be used in _document.

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…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Elindo586
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@icyJoseph
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants