DEV Community

Cover image for Comparing Gatsby and Next.js for website development

Comparing Gatsby and Next.js for website development

Alex Barashkov on February 22, 2022

Gatsby and Next.js, from a first glance, could look pretty much the same. Both are React-based frameworks, do SSR, SSG, have big communities. We ac...
Collapse
 
damsalem profile image
Dani Amsalem

I’ve recently began building a blog using NextJS and Sanity as the CMS. Coming from original WordPress and some basic PHP/Twig sites, it’s quite a change but I’m really enjoying the workflow.

It seems a good CMS like Sanity can take care of several issues you brought up such as image optimization, easy CMS integration, and previewing content.

I was considering using WP as an initial proof of concept but opted to just use Sanity and deploy it all in Vercel.

Collapse
 
tzm profile image
Stamen Georgiev

It's far beyond me why someone would use such a framework.
You are building STATIC pages with React. Think about it. Static. React.
And then you serve all your content as html. And then you serve it again as JSON to hydrate the page. High performant you say? Look at the TTI and the cpu load when all that javascript and JSON data comes and needs to be parsed and evaluated.
I have to deal with this gatsby crap on daily basis. Slow build times. Fucked up HMR.
Do you know that in dev mode Gatsby serves all the CSS that it finds in the project so you have to think how to scope everything so you can develop normally?

Don't do this to yourself. This abomination needs to die.

Collapse
 
psalaun profile image
Pierre Salaün

Astro should be the best of both worlds, but I haven't tried it yet: write your pages with React to get the easy componentization of everything, ship pure HTML/CSS with JS only where it's needed for interactivity.

Collapse
 
codewander profile image
codewander

i personally like next.js and vite-plugin-ssr.

Collapse
 
eleloi profile image
eleloi

It is not possible to have Auth capabilities on Gatsby?

Collapse
 
alex_barashkov profile image
Alex Barashkov

It’s possible, but experience will be less pleasant. Next.js has much more tutorials and examples related to this topic and also there is a very nice next-auth library that does a great job.

Collapse
 
anothertobi profile image
Tobi

But afaik you can't use ssg with next-Auth. That's why decided against it

Thread Thread
 
lavgup profile image
lavgup

Yes, you can!

Thread Thread
 
anothertobi profile image
Tobi

Even with custom Auth pages?

Collapse
 
ronaldaug profile image
ronaldaug

Based on my projects, most of the time, Auth are handle in headless API.

Collapse
 
qurus profile image
Eli

Nextjs is way much faster than gatsby. All those plugins for gatsby not maintaining well. I will learn SDK better instead of wasting time with gatsby plugins.

Collapse
 
shifi profile image
Shifa Ur Rehman

Gatsby does a lot of things by default for you. That can be a pro for a newbie or an intermediate developer. Plugins only increase the curiosity. But for some people that's exactly the problem. When they can't control the complex behavior of something people seem to get annoyed and would like to write their own solutions. It's exactly just like a debate between using a frontend library or to write one's own css instead.

Having the flexibility of complex control sure does bring in the heat of doing everything by your own hands.

Now Gatsby is good, definitely good. Maybe on par with nextjs. But the real power of nextjs is the "barebones-ness" relative to gatsby and you'll see some very professional and expert developers advocating for that.

It was a nice read though. You really did a great job explaining the differences ^^

Collapse
 
alexadark profile image
Alexandra Spalato

You can also use gatsby "barebone" and write everything custom if you like, plugins are just an option to not reinvent the wheel not an obligation.
IMO it's really nice to have the option to use these plugins

Collapse
 
andrewbaisden profile image
Andrew Baisden

Next.js gets my vote its more popular than Gatsby now with a bigger more active community. The speed is also better in my opinion.

Collapse
 
johnson478 profile image
john johnson

According to my projects, headless APIs are typically used to manage authentication. you can try this out to know why every student should read the great gatsby. The essay is a remarkable story that appeals to students for a variety of reasons. It is really relatable to both adults and children. You may see a little part of yourself in each character when you examine them.

Collapse
 
budibase profile image
Budibase

For simple static sites, Hugo rocks!

Collapse
 
julrich profile image
Jonas Ulrich

Nice article, I think you've hit all the major points on the head!