r/reactjs • u/Triptcip • Aug 21 '18
Next vs Gatsby?
I am trying to decide whether to build my website in Next or Gatsby and would lik your opinions please.
The app I am looking to build is a job website. You can search, apply and create jobs as well as login with different user types.
I would like it to be SSR for SEO purposes as well as some performance improvements.
It is powered by a graphQL API and I am planning on using Apollo client which I assume should work equally well with both Next and Gatsby.
My first impression of Gatsby is that it is more of a static site generator which I interpret as being aimed at content or marketing websites and not as focused on web apps. That is a complete assumption so please correct me if I am wrong.
I know Next is well established with great documentation and developed for the purpose of building web apps.
What would you recommend? Is one easier than the other? Do they both cover the same use cases?
I'm interested in hearing everyone's opinion.
18
u/znakyc Aug 21 '18
As you say they are two different tools: gatsby is a static site generator which means it doesn't use a server. It just generates static HTML/Js. Next on the other hand, is running a server and renders HTML dynamically.
So wether you should use gatsby or next depends on your use case. Do you need a server? If you want to dynamically call an backend API every time there is a new request to generate the HTML, then you probably need a server. If your content changes a lot, like I would imagine a job site does, then you can't only rely on static content. You must probably fetch the job data from a db. So I would go for next.js given the little info I know about your app.
5
u/lowdown Aug 21 '18
They are both great choices. Gatsby gets you more “free” out of the box and the starter/plugin ecosystem is amazing.
Next gives you less structure and more opportunity to tailor it for your needs.
Either would work well connected to GQL as a web app.
66
u/timne Aug 22 '18
Upfront disclaimer; I'm the lead maintainer of Next.js.
So to answer your questions one by one
This is a great first step, thinking about SSR before building your app can avoid hurdles mid-way through a project.
One example of why SSR is important for SEO: https://twitter.com/kgblanchette/status/1029814228541218817
At Google I/O earlier this year there was a talk called "Deliver search-friendly JavaScript-powered websites":
This talk goes into high level details of how Google crawls Javascript apps. I recommend watching the whole talk, but I added a timestamp at the most interesting part, which explains that server-side rendered sites get crawled immediately vs javascript apps getting deferred for up to 3 days till resources are available:
https://youtu.be/PFwUbgvpdaQ?t=13m53s
We currently have over 150 unique examples which are frequently updated by the community, one of them is how to implement Apollo with SSR:
https://github.com/zeit/next.js/tree/canary/examples/with-apollo
There are some great answers to this question in the whole thread already.
Just to clear up the Next.js side:
Next.js has 2 "pre-rendering" (server-side rendering) modes:
- On demand rendering means for every request that comes in you render a unique page (It's still possible to cache this response ofcourse) This is great for highly dynamic web apps in which content changes often, you have a login state, and similar use cases. This mode requires having a Node.js server running. Examples of this are zeit.co, marvel.com, deliveroo.com, jobs.netflix.com, and opencollective.com (more found here: https://spectrum.chat/?t=e425a8b6-c9cb-4cd1-90bb-740fb3bd7541)
- Render all pages to
.htmlfiles up-front and serve them using any file server. This does not require you to have a Node.js server running and the html can run anywhere. An example of this is nextjs.org, carbon.now.sh, plot.ly, material-ui.com, and vergecurrency.com (more found here: https://spectrum.chat/?t=e425a8b6-c9cb-4cd1-90bb-740fb3bd7541)These modes can be switched between (they're separate commands) as you can read in this comment: https://www.reddit.com/r/reactjs/comments/98lm2n/comment/e4i90qk?st=JL3QZVZT&sh=dd3b14c2
One thing that large scale companies use is the "zones" feature, the engineers from trulia.com had a talk about this subject at ZEIT day San Francisco earlier this year: https://www.youtube.com/watch?v=f7BMSVhZan0
I hope this answers your questions, if not feel free to ask more questions here, on our spectrum community or direct messaging me on spectrum here
23
u/Castas Aug 21 '18
I talked about my experience with both in another post https://www.reddit.com/r/reactjs/comments/98lm2n/comment/e4i90qk?st=JL3QZVZT&sh=dd3b14c2
tl;dr Gatsby is great if a dev owns the site and it isn’t too large. Next is better for a larger site or if you’re building an app
11
u/its_j0hn Aug 21 '18
Don't be afraid to use Gatsby even if your site is full of dynamic data! The way I use it in many of my apps is I utilize Gatsby to statically generate the "shell" of my application and dynamically fetch data in
componentDidMountjust as you would in a regular SPA. I've found Gatsby to be a fantastic starting point for robust PWAs. Check out this blog post I wrote. Although it uses v1 of Gatsby, much of the info is still relevent.11
u/vcamargo Aug 22 '18
I might get some hate from it, but I'll share anyway. Last time I tried Gatsby I wasn't able to run the official demo in less than 30 minutes so I gave up (I was just trying it out of curiosity). I've written a considerable big project with Next in my last job and the technical decision to go with Next was mine, that been sad I have to say that I truly regret. Simple stuff like query parameters was a ugly hacky work around, flash of unstyled content was a real issue and not easy to solve. It didn't talked well with other React libraries (tbh I don't think it's a problem with Next only). Lots of boilerplate and not so clear configurations to tackle non trivial tasks. I don't think all the magic that's underneath it really pays off. We ended up with a custom Webpack configuration anyway, that's something I tried to avoid because webpack can be huge time consuming pita. They have this example directory in the repository with lots of helpful stuff but we had to mix 4 or 5 of these examples to fulfill our needs and that was a ugly mass hard to maintain. It was almost 5 months ago so things might have improved. But I'd definitely do my SSR setup myself if I'd start today.
Here are some issues that were difficult to solve, are still unsolved or the proposed solution did not helped us that I remember:
https://github.com/zeit/next.js/issues/2833
https://github.com/zeit/next.js/issues/3362
https://github.com/zeit/next.js/issues/299
https://github.com/zeit/next.js/issues/3257
In hindsight I believe it still is the best out of the box solution for the SSR issue with React and the team is amazing.
14
u/trojaniz Aug 21 '18
Check out Razzle too. I prefer that to Next, but it seems the industry might think otherwise.
2
u/jonny_eh Aug 21 '18
Also consider RogueJS, it's like Next but is less opinionated, let's you use React Router.
https://github.com/alidcastano/rogue.js/
•
u/swyx Aug 22 '18
I am going to put this on the sidebar as this is a very common discussion that we have here. the alternatives to Next and Gatsby people suggested are also worthwhile
i can't pin somebody else's post but everybody go read /u/timne's post below, most excellent:
https://www.reddit.com/r/reactjs/comments/992n2r/next_vs_gatsby/e4lrffl/
need somebody from the gatsby side heheh
2
u/brillout Sep 10 '18 edited Oct 31 '18
Check out the alternative Reframe (https://github.com/reframejs/reframe). It can do both static sites and SSR.
I'm Reframe's author and I've started Reframe because I wanted a web framework that is truly flexible.
To get a glimpse of how Next.js is not flexible, see vcamargo's comment above: https://www.reddit.com/r/reactjs/comments/992n2r/next_vs_gatsby/e4lwqrd/
As for Gatsby, well, it's an inherently crippled stack: By design, all dynamic content needs to be rendered on the client (i.e. no SSR for dynamic content). This means poor performance on mobile, loss of control over SEO, and no SMO at all.
It seems like SEO is important for your app and that your content changes frequently meaning that Gatsby is of no use for you.
8
u/trout_fucker Aug 21 '18 edited Aug 21 '18
Both are good, I prefer Gatsby because it's less opinionated.
They are both static site generators and can do pretty much the same stuff.
Edit: can anyone tell me why this is getting downvoted to oblivion?
3
u/XiMingpin91 Aug 21 '18
Well as you say Gatsby is a static site generator, so you're correct in your assumption about it being for websites vs web apps.
It sounds like what you want is a full blown web app, so I would personally go with Next. Gatsby is more suited to sites that purely display information and have little interactivity. See React docs for an example of Gatsby in the real world (the React docs website is built with Gatsby).
2
u/jwindhall Aug 21 '18
You can certainly build an “App” with Gatsby. I’ve used both. I really like both. Advantages and pitfalls of each. Depends on what you’re looking for. It’s worth noting that Gatsby comes with graphql out of the box — no need to set up Apollo. Next on the other hand does not and is far less opinionated in general.
2
u/[deleted] Aug 21 '18
Dynamic content with user login and profiles? Don't go with a static site generator under any circumstance. If you do, you will soon find yourself in a situation where you need more flexibility than a static site has to offer, and then you end up starting over. If you're mostly doing a prototype / proof of concept, that may be acceptable. Just know that if you want this product to evolve, you will meet a dead end.
1
u/swyx Sep 11 '18
related post https://www.reddit.com/r/reactjs/comments/9ew9cu/how_to_get_react_seofriendly_by_using_nextjs/
1
u/[deleted] Aug 21 '18
https://react-static.js.org/
1
u/stolinski Aug 21 '18
IMO they are very different use-cases. A Next site would have content that's being updated frequently where a static site like Gatsby would be best for data that's updated less frequently. Gatsby is great for portfolio sites, blogs, landing pages, stuff that's not updating constantly. Next is much better for things that are way more dynamic.
1
u/Zeeesty Aug 21 '18
you answered your own question here I believe.
10
u/[deleted] Aug 21 '18
[removed] — view removed comment