DEV Community

Cover image for 5 reasons to consider Next.js for your next projects
teri
teri

Posted on • Originally published at hackernoon.com

5 reasons to consider Next.js for your next projects

What are your best choices when choosing a JavaScript framework for your next project?

Whether it is a weekend project or you want to build a complete production app that is performant to users logging on to your website.

First, let's discuss what Next.js is, why it became popular, and the benefits you gain as a frontend specialist.

What is Next.js

The purpose of building and designing a framework aims to make building web applications faster. Next.js is a framework built on React that gives frontend developers the flexibility of creating modern and scalable apps by allowing developers to render content on the server. Also, with Next, it can be extended to become a full-stack framework that provides Node servers through the api directory within the pages folder.

GitHub logo vercel / next.js

The React Framework

Next.js

Getting Started

Visit https://nextjs.org/learn to get started with Next.js.

Documentation

Visit https://nextjs.org/docs to view the full documentation.

Who is using Next.js?

Next.js is used by the world's leading companies. Check out the Next.js Showcase to learn more.

Community

The Next.js community can be found on GitHub Discussions, where you can ask questions, voice ideas, and share your projects.

To chat with other community members you can join the Next.js Discord.

Our Code of Conduct applies to all Next.js community channels.

Contributing

Please see our contributing.md.

Good First Issues

We have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Authors

Why the popularity?

The popularity of Next.js is due to its rendering technique by choosing how to render content on the page. It could be either of the following:

  • Static site generation (SSG) - all content is prebuilt on the server and passed onto the client, which is cached. SSG means that at build time, HTML is generated (pre-downloaded). An example is a blog post website.
  • Server-side rendering (SSR) - Generate the site on the server if you want fresh data on page refresh. Each time you refresh the page, you render the content and refetching the data again. Examples of SSR are dynamic news feed and movie sites like Netflix.
  • Incremental site regeneration (ISR) - ISR combines the best of SSG and SSR. That means you can generate the page in advance as part of the build process and also be able to refetch new data like in SSR and ISR.

Benefits of Next.js

Some of the other benefits of Next include:

Performance

Next provides some features that make building a performant website a breeze, so you don’t have to worry as this has already been bundled with the necessary project files to build your app. Some of these features include:

  • Code splitting: Just like separating the files into different components. Code splitting is dividing your web app into small chunks so you can only load the chunk used by the current page.
  • Minifying files: Reducing the app's file size makes it more performant using next build.
  • Image optimization: The Image component that Next.js provides automatically optimizes images based on screen sizes instead of using the <img> element.
  • Pre-fetching assets: As you scroll down a page built with Next.js, the page lazy-loads assets onto the screen.

File based routing

Routing is the navigation between pages, meaning that every Next.js application comes with a pages directory. You get a new route once a file is created under the directory, like index.js, as the default root page route.

Unlike React, Next.js don’t need an external package like React Router before creating routes. It comes out of the box during the installation of the boilerplate. Also, file-based routing improves the app's performance by loading only the specific route and resources needed for that route.

Next.js routes

The other routes Next.js provides are nested routes, /grocery-store and dynamic routes, /grocery-store/[id].

Dynamic routes uniquely identify a specific page with the bracket syntax signifying that the page keeps changing, which defines the dynamic route.

Search engine optimization (SEO)

SEO is the language for bots. The search engine result page (SERP) like Google crawl, index, and rank your page based on content and other determining factors like the title, page description metadata, image alt tag, semantics like using headings, <h1>, <h2>, <p> tag for text, and so on.

Now, what is SEO? SEO is increasing the quality of traffic and quantity of a website through organic search results. In Next.js, pre-rendering will generate HTML for each page in advance instead of having it done by the client-side JavaScript to help with better performance and SEO.

Next head component for SEO

Serverless functions

In layperson's terms, running your Node.js code in the same codebase as Next, a user makes a request, and the serverless function kicks into action and starts the server. Once it executes that specific function, which is the request from the user, it shuts down the server since no other activity is taking place within the codebase. Next is the React framework for production, as both the frontend and backend are written in the same codebase making for good architecture by software developers.

Anything under the api directory automatically has a node server configured already communicating with the client-side from the backend on the same application.

Serverless functions

Conclusion

This article summarized some of the benefits of choosing Next.js as it scales perfectly to meet your requirements for any project idea you have.

Explore some of these features, as the official documentation offers much more to learn.

Learn more

Top comments (0)