1

I downloaded html css template and trying to integrate in "nextjs". What is difference between "_app.js" and "document.js"? where should i use/include "css, js" files? either in "_app.js" or inside "document.js" ?

1 Answer 1

3

As nextJS docs specify related to _app.js:

Next.js uses the App component to initialize pages. You can override it and control the page initialization and:

  • Persist layouts between page changes
  • Keeping state when navigating pages
  • Custom error handling using componentDidCatch
  • Inject additional data into pages
  • Add global CSS

Next page of the docs also specify that _document.js is:

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.

So basically your global css should go in App.js. However if you need to import certain CDN styles for some libraries I suppose you can do that here as well (but you should probably consider using just _app.js for this as well as it can be seen in this example)


Regarding the JS question as wikipedia states:

Next.js is an open-source web development framework created by Vercel enabling React-based web applications with server-side rendering and generating static websites.

So basically you should import React components where you need them, but I would recommend you to follow a tutorial if you need to learn more about React (There are a lot of beginner NextJS tutorials that can cover this).

Sign up to request clarification or add additional context in comments.

2 Comments

so me should put my css and js files inside "_app.js" ? am i right ?
For most cases, and if we are talking about generic css and js files, yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.