13 reasons why you should use Nextjs
In this blog post I will explain 13 reasons why you should use Next.js.
Now, why should we use it? Simply because it solves our problems. So let's see the problems that Nextjs solves for us.
SEO: One of the most drawbacks of client-side rendering is poor SEO. Because in CSR you don't have any content on your HTML page. All content is rendered by the javascript. That's why search engines don't give you give search engine optimization. So, we need server side rendering. And Nextjs allow us to do that.
Server Side Rendering: Client side rendering has a bunch of problems like SEO, huge bundle size, slow initial load, and blank page flickering. Server side rendering doesn't have that problem. And we can use server side rendering with nextjs.
Static Site Generation: Suppose you have a blogging website. In this type of website the content hardly changes after it gets deployed. So you don't need to fetch any data from the client or server side. Everything is present on the html and CSS. So the browser only needs to parse them and maybe a little bit javascript. This type of website we called static sites. They are super fast because they have fewer tasks to complete. With Nextjs, we can generate out static html on build time and we don't have to worry about it anymore.
Client Side Rendering: Yes, you can also do Client side rendering in nextjs. If you want to have single page application that doesn't refresh, well you can have it here. You combine the 3(CSR, SSR, SSG) rendering systems in Nextjs. You provide your static HTML or fetch data from
getStaticProps
which will be treated as static html. So you can have SEO. Then you fetch the necessary server side data from thegetServerSide
function. And lastly, you can use any client side data fetching method. And that's how you can have a combination of 3rendering systems.
I have already made a video about client and server side rendering. You can check them out.
Image Optimization: Image is very important for our website. It can make the user experience so much better and also it can make our website super slow. So we need to optimize our images. And Nextjs here is to help us. With Nextjs
Image
component, we don't have to worry about optimization. It will do all the work for us. It can make our:- Image size is smaller while keeping the quality good.
- Lazy load our images.
- Responsive images based on the screen width.
Built-in Routing: It has a built-in routing system. You don't need to install any external package. It gives you all of the features out of the box.
Built-in CSS Support: With Nextjs you can:
- directly import your css files.
- import styles from
node_modules
directory. - use component-level CSS with CSS Modules.
- Use any existing CSS-IN-JS solution.
- Nextjs support Styled-jsx out of the box.
code with styled-jsx:
1function HelloWorld() {2 return (3 <div>4 Hello world5 <p>scoped!</p>6 <style jsx>{`7 p {8 color: blue;9 }10 div {11 background: red;12 }13 @media (max-width: 600px) {14 div {15 background: blue;16 }17 }18 `}</style>19 <style global jsx>{`20 body {21 background: black;22 }23 `}</style>24 </div>25 )26}2728export default HelloWorld
Api Routes: So you need a back-end server for your website. But the work is not too much. Setting up a server for a small amount of work is too much work. Again Nextjs comes to the rescue. It has a feature called API routes. It will allow you to build your API. You can not only implement REST but also Graphql.
Internationalized Routing: Nextjs has built-in support for internationalized (i18n) routing. Let me explain. Suppose you have a website in English and another language. If someone visits your website from Bangladesh, then you want your website language to be in Bengali. If someone visits Korea, then you want it to be Korean. I hope you are getting my point.
Code Splitting: Nextjs has Code splitting feature out of the box. If you don't know what it is then check out this blog ---> What is code splitting? by me. It simply splits the code into separate bundles to make the load faster.
Satic Assets: It has a directory called
Public
where you can store all of your static files like SVG, image, video, etc.File System Routing: It has a file system routing. There is a pages directory where you put all of your page files. Like you are storing HTML files. That makes things easy to handle.
Highly Configurable: If you have used create-react-app, then that you can't change the config. You have to either eject the project or apply some methods which are hard to do. But if you know webpack, then with nextjs you can configure your application with a single config file.
This is why you should use Nextjs. Nextjs is the most popular framework for React because of its awesome features. And there are more things to explore.
Shameless Plug
I have made an Xbox landing page clone with React and Styled components. I hope you will enjoy it. Please consider like this video and subscribe to my channel.
That's it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.
Contacts
- Email: thatanjan@gmail.com
- LinkedIn: @thatanjan
- Portfolio: anjan
- Github: @thatanjan
- Instagram : @thatanjan
- Twitter: @thatanjan
Blogs you might want to read:
- Eslint, prettier setup with TypeScript and react
- What is Client-Side Rendering?
- What is Server Side Rendering?
- Everything you need to know about tree data structure
- 13 reasons why you should use Nextjs
- Beginners guide to quantum computers
Videos might you might want to watch: