2

Next.js Vs. Gatsby: What Is The Best Choice In 2021

 3 years ago
source link: https://hackernoon.com/nextjs-vs-gatsby-what-is-the-best-choice-in-2021-w91134om
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Next.js Vs. Gatsby: What Is The Best Choice In 2021

4
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png

@dimamiroDima Miro

Founder of Unikorns Agency | Jamstack fanboy

When starting a new project I’m often finding myself choosing between Gatsby and Next frameworks. So I decided to write a little post about what those things are for and what to choose in 2021.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

I started my journey with Jamstack from Gatsby thanks to my previous team leader which initiated rebuilding a company website using Gatsby as the main framework.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

It was an amazing experience. I fell in love with Gatsby as a framework and Jamstack as an approach almost from the very beginning of coding. And when I decided to run a web agency I pushed Jamstack as a primary architecture and Gatsby as a primary framework to use. I didn’t even want to hear that there are alternatives. Gatsby — one love, that’s what I thought at that time.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

But the time was passing by and the team started to look around, then we noticed another great React framework Next. Quite similar at the first glance but different at the same time when looking deeper.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What are Gatsby and Next all about?

Well, both frameworks are created on top of React. What does it mean?

0 reactions
heart.png
light.png
money.png
thumbs-down.png

It means that you have all React foundations that give you a create-react-app boilerplate plus additional features, toolkit, and guidelines of how the app should be coded on top.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

As I mentioned above, at the first glance they are both fairly similar as they:

0 reactions
heart.png
light.png
money.png
thumbs-down.png

create an app from boilerplate allows coding a website significantly faster with awesome developer experience generate SEO-friendly and super-fast websites

0 reactions
heart.png
light.png
money.png
thumbs-down.png

But there are two common beliefs:

0 reactions
heart.png
light.png
money.png
thumbs-down.png
  • Gatsby.js is for static content only. While some time ago it would be used only for static content that will be stored in CDN, now Gatsby.js offers a complex product that may be used for both static websites and dynamic apps. The glory of Gatsby.js as a static-site generator haunts its creators as they have to make a webinar to dispel this.
  • Next.js is a server-side rendering only framework. Well, maybe once upon a time in a faraway galaxy, but definitely not nowadays. From v9.3 we can choose what approach to use: server-side rendering or static site generation.

They rapidly evolve and become kind of monsters.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What do we get on start?

Let’s start from the very beginning. We generate a new project, open it, and… see a boilerplate structure that both frameworks kindly prepared for us. Same at the first glance but a little bit different.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Public assets

The folder named public contains built files in the case of Gatsby.js and static assets in the case of Next. The last one creates a .next file for built files.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

In both boilerplates, we also have config files where we can provide settings for the project. Both generate different files for us. In Gatsby, a lot of things are going here. All because of plugins.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Plugins, addons, and libraries

They build the plugins ecosystem around its functionality and community, which is an important feature you’ll definitely notice as it increases the work speed. Imagine you have a plugin for everything, with a minimum setup time, just paste the code and implement almost every external integration. Cool, isn’t it? I’m sure it’s a killer feature for many devs.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Next doesn’t have this kind of functionality, but both frameworks support all React libraries. In a nutshell, you can implement your integrations in both frameworks, it’s just a case of extended time in Next, but Gatsby does it faster (depending on the complexity of integration, obviously).

Routing

And routing. There is a folder “pages” where all our page components will live. Pages will be automatically generated with names of components inside this folder. You should use special link components to route between internal pages.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The rest of the file structure is not really important as you’re free to organize it as you wish: components, context, utils, etc.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

How does coding feel?

Both frameworks were created to make developer’s lives less stressful. Both take care of routine things and allow us to concentrate on the sense of code. They allow us to just create.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Documentation

The learning of both frameworks is not a hard thing if you already know how to build React-based projects. Both Gatsby and Next have comprehensive documentation and a lot of tutorials. Just jump into it and get things done!

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What makes Gatsby cool?

In my opinion, Gatsby.js burst into the room just like Jackie Chan and turned the game around. It has a lot of features, a full list of which you can find on their website. I want to mention my favorite ones.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Gatsby plugins (again)

0 reactions
heart.png
light.png
money.png
thumbs-down.png

I’ve already mentioned that Gatsby built an ecosystem of plugins. You can find a plugin for almost everything you need: a lot of gatsby components, gatsby-source plugins, gatsby-integrations, etc. Everything is in their plugin directory for free.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

GraphQL for everything

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Another amazing thing in Gatsby — GraphQL for all queries. Inside and outside of the project. I had to use it, but now I found it very useful. You can always check your queries in GraphQL Playground that is running together with your project on localhost.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Image optimization

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Last in this post but not least — Gatsby.js offers image optimization. They prepared an amazing component called gatsby-image, and this component does everything we need for image optimization. And it has an awesome blurred effect when an image is loading.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Gatsby community

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Don’t forget about community and support. It’s an important part when choosing a framework, and I would say that both Gatsby.js and Next.js are doing a great job towards community building. In the case of choosing Gatsby.js, you can rely on their Discord community. You can always find an answer and just chat there.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What makes Next.js so good?

Next.js doesn’t have special plugins and doesn’t use GraphQL out of the box. It has a special image component too, but it doesn’t have a blurred effect 🙂

0 reactions
heart.png
light.png
money.png
thumbs-down.png

But Next.js has a lot of other features which make it a favorite of many.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Serverless functions

0 reactions
heart.png
light.png
money.png
thumbs-down.png

For example, “api” folder is generated from the start. I didn’t mention it in the previous block, but it’s worth it for sure. Every js file in this folder will be executed as a serverless function when a project is hosted on Vercel or Netlify. These functions handle logic like user authentication, form submission, database queries, custom slack commands, and more.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

SSG + SSR. What?

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Another great thing in Next.js — a hybrid approach. That means that you can combine static site generation (SSG) and server-side rendering (SSR). We got this possibility starting with the 9.3 release and I also found it very useful.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The sophisticated way for updating the content

0 reactions
heart.png
light.png
money.png
thumbs-down.png

There are a lot of other great features which you can find in their documentation. I want to mention only one more — incremental static regeneration (ISR). Long story short, if you want to get an idea of that, I suggest jumping into the article written by Lee Robinson for Smashing Magazine, where he explains everything about ISR.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Next.js community

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Vercel, Next.js’s parent company, hires ambassadors that make high-quality content for the community. I’ve already mentioned Lee Robinson here, and I suggest taking a look at his YT channel, blog, and Twitter. There is a lot of worthwhile information out there.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

What will we get in the end?

When your project is compiled you will get a fast and SEO-friendly website or app. You just have to choose the appropriate hosting platform (Vercel, AWS, Netlify, Cloudflare, etc.) and here we go. Your project is live!

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The hosting platforms is a topic that worth making a separate comparison post, which is on my plans. One thing I want to add is that both companies behind those frameworks have their own platforms: Gatsby Cloud and Vercel.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

And the conclusion:

Although Next.js may look like taking leadership, for me, there is no winner in this competition. You can endlessly count the pros and cons of both. In Unicorns, we use both frameworks, and it mainly depends on project needs and structure. Moreover, according to Gatsby’s own comparison, those frameworks are both taking into consideration basic parameters, so it’s mainly a case of personal preferences and skills.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Hope you enjoyed this article and stay tuned!

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Previously published at https://agilitycms.com/resources/posts/gatsby-or-next-js-what-to-choose-in-2021

0 reactions
heart.png
light.png
money.png
thumbs-down.png
4
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
Join Hacker Noon

Create your free account to unlock your custom reading experience.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK