What is Next.js: A Comprehensive Guide to its Advantages and Why It's the Future of Web Development
Bonface Maina
Software Developer | web designer | Senior React, Go, Nextjs and Django developer | app developer
What is Next js:??????
You might be wondering what is this next js everyone is talking about and why you should bother learning it? .
Next js is an incredibly powerful framework for building fast and search-engine friendly applications. By a framework mean next js handles the tooling needed for React, even react team themselves recommend next js or Remix but in this case our focus is on Next js.
Next js is build on top of react so everything you know about react is relevant even though next js helps you get to the next level.??
While react is just a library for creating interactive user interfaces, Next js is a comprehensive framework.. Think of it like this React is just like a car without an engine and Next js builds on top of the car and includes everything. ??
Why use Next js and not React alone??
- Next js has it's own Built-in routing library, so we don't need to use separate libraries to route in our applications like we used to do when working with react e.g react-router-dom. Adding more libraries adds dependencies that are unnecessary like think of it this way if the routing library has an issue your website won't work properly or you'll need to update the dependencies but with next js there is no such issue since routing is build in it.
- It comes with it's own compiler for transforming and minifying our javascript code. It also has Automatic code splitting which improves load time of your application.
- Built-in API routes. Imagine you can write your own api routes inside the same codebase? ?? If you are shocked I was also too. Next.js allows you to build your API routes, providing a solution for backend functionality directly within your Next.js application. React does not provide this feature.
- Image optimizations. Next js comes with a built-in image optimization feature which improves performance.
- SEO friendly. Next.js is more SEO friendly than React due to its server-side rendering and static site generation capabilities. This can be beneficial if SEO is a priority for your project. SSG and SSR explained below
SSG (static site generation) and SSR (explained)
Next js comes with a command line interface for building and starting our applications and it also comes with a node js runtime..
But what is a node js runtime??
well there are two ways to execute JavaScript code
- Within the web browser in the client just as React does it....
- In a node js runtime on the server..
领英推è
But how does this help??
Okay node js runtime is a fancy term for a program that can execute js code
Next js allows us to do some cool stuffs with this server runtime thing..
- We can do fullstack development.. just like mentioned above.
So in typical react applications we need a frontend built using react and a completely different backend build with another language or technology or same (JS).
But in next js the node js runtime allows us to render our components in the server and send the content to the client. This is the technique called SSR => Server Side Rendering..
SSR typically means that the components are rendered in the server and the content which is html is sent to the frontend which means we offload all the hefty tasks of rendering from the client and the client only shows the content which is extremely fast..??
With next js we can also pre-render components that have static data.
So pre-rendering means that a component is executed when the website is being build with lets say $ npm run build the contents of an executed website is normally html and css and some javascript used only for functionality but not rendering a component.. This techniques is called SSG => Static Site Generation
This improves the SEO of our applications and makes them blazing fast..
In a nutshell nextjs is a framework for building superfast and search engine friendly applications..
#nextjs #react