Learn
Turtle
Gatsby vs Next vs Create react app Comparison
Gatsby vs Next vs Create react app Comparison

Gatsby vs Next vs Create react app Comparison

A beginner's take on the most popular React toolchains out in the market.

image

When vanilla JS beginners start to feel that they have become mature enough to play with some serious code now, they usually head to frameworks. I've seen newbies use as heavy scaffolds as Angular to create basic forms. And this compels me to write a piece on why you shouldn't do that, and how you should judge a piece of code before using it.


No matter whether you've just begun coding or you have had years of experience building applications, not having carried out proper research can seriously damage the present as well as the future of any project that you undertake. And this research includes choosing the most suited languages, frameworks and toolchains for your project, depending on the requirements at hand.

This article is going to cover the entire process of choosing the best candidate among the top 3 ReactJS based toolchains - create-react-app, Next.js & GatsbyJS

image

Whats the difference?

Before we begin benchmarking each toolchain against the various use-cases that they're all built for, we need to understand what makes them different from one another? After all, they all are built on top of ReactJS, and use React under the hood to publish web-apps. Then why are they not used interchangeably with one another?

For starters, each of the three candidates are toolchains which means that they are only relevant to packaging and publishing code, and have no absolutely no role in altering the way in which the app is designed. This means that these toolchain come into play after a web app's structural design is ready. However, it is important to decide on a toolchain as soon as possible because every toolchain has its own set of requirements to be met by the code design. And if this is not planned properly prior to development, then it poses a risk of sending the dev team into a refactoring phase, which can sometimes last longer than even the initial development phase.

image

create-react-app

This was built by facebook, the original makers of the React framework. The official docs state this to be the easiest way of creating a React SPA if you're someone who is trying out React for the first time. Learn create-react-app

image

Next.js

This is a popular toolchain for building React apps. However, rather than exporting SPAs (Single Page Applications), Next.js exports a server-side rendered web app, which can be deployed on a server to allow server-side rendering of your app, which eliminates a lot of issues that are cause by client-side rendered apps such as inability to handle external links, limited SEO support etc. Learn Next.js

image

GatsbyJS

This is a toolchain whose popularity has been rising quite lately. It is backed by an awesome collection of community-contributed content including blogs, tutorials, plugins and much more. It allows pre-rendering a website, which means that the React code is directly built into static HTML + JS files, allowing them to be served via static servers, achieve great levels of performance, and also enabling SEO & SMO. Learn GatsbyJS

Let's begin!

Instead of setting out high quality benchmarks such as rendering time, loading time etc, I will be comparing these frameworks against their most common use-cases. This sort of comparison generally tends to be more friendly for beginners.

So here's the list of general use-cases for a React web app -

  • Simple, static web app
  • Large websites with dynamic content, such as Medium
  • Purely Single Page Apps, such as Gmail, GDrive
  • Complex isomorphic apps, which involve both CSR & SSR, such as Twitter, Facebook
  • image

    Simple, static web app

    A static web app generally requires to be:

  • Compact, with not more than 15-20 webpages
  • SEO-friendly, to allow better discovery on the web
  • With static web apps, updates don't necessarily require to be fast, however, fast updates will always be a major pro.

    For static websites, Gatsby is way better than any of the other contenders. With the awesome pre-optimized starters, beginner friendly documentation, huge support for CMS plugins and pre-rendering of all pages, Gatsby can help you set up a custom website for a routine task such as a blog, or a product landing page quite quick & smooth. The pre-rendered HTML built by Gatsby can be deployed anywhere, with GitHub Pages & Netlify being the top choices for static site developers.web

    However, one important point that such comparisons often miss out on is that Gatsby creates an renders every single page of your app to static HTML while building. This means that all of your 15-20 webpages are sequentially created by the toolchain while building the app. It is quite evident that this can become a major issue if the site grows large enough, given that some of the CD build environments (Yep, I'm talking about Netlify) are notoriously slow.

    Deploying a Next.js app for a 15-20 pages website would be an overkill, in my humble opinion. Unnecessary server side rendering will decrease your web-app's performance, and you'd certainly not want to lose audience just because your blog loads slow.

    Verdict: Gatsby Reason: Optimized performance, developer experience and build time.

    image

    Large website with dynamic content

    Now that your website has started to grow, and you've shifted to something more interactive, you'll slowly realize that you're spending a lot more time while watching your app build after every upgrade if you continue to use Gatsby. Also, you will start facing problems with loading dynamic content easily (Gatsby confuses Firebase). To handle these things better, it would be easier to shift to Next.js as Gatsby is explicitly a static website generator

    On a sidenote, it is practically impossible to compile dynamic changes to a static website. So you either need to use an external backend, or handle simple logic through SSR-based Next.js

    Verdict: Next.js Reason: Faster content updates, pure SSR

    image

    Single Page Applications

    SPAs generally dont require to be SEO optimized, or handle external links. They are usually meant to be heavily client-side rendered, to carry out client based operations. External links in an SPA can still be implemented using an appropriate server environment. The most important requirement for an SPA is to be fast and responsive to the user.js

    In this use-case, Gatsby & Next both level out. This is because of the way that they are designed.

    Apart from being a static site generator, Gatsby has a nice little feature called React injection using which, static sides created by Gatsby are injected with React framework upon loading. This means that it is not completely static, and it still has access to the most robust features of React such as virtual DOM. This is what greatly increases the performance of sites made using Gatsby.

    Also worth noting that Next.js too has a nice little feature, which allows it to serve static as well as dynamic webpages. This means that everytime an app is built in Next.js with multiple pages, all those pages are assessed by the Next frameworks and pages which do not have any dynamic content are generated & served statically. This reduces the interactive time delay associated with Next and thus improves its performance on the whole.

    Verdict: Next AND Gatsby Reason: Comparable features & metrics in this use case

    image

    Isomorphic Apps

    Isomorphic or Universal apps (I know they're different) generally involve a lot of dynamic content. Almost all of the content on giants such as Twitter & Facebook is dynamic. This simply means that they can not function even with a client side React injection such as Gatsby's. Although Gatsby can still handle this, but it is beaten out by Next in some cases such as first meaningful paint. Also, SEO for a large isomorphic app is much more easier in Next than in Gatsby. So Next is the clear winner here.

    Verdict: Next.js Reason: Better SEO, public accessibility, and performance optimization

    The Final Verdict

    There can not be one answer to what's the best toolchain for React. It always depends on how you plan to use them. Here's a list of most common use-cases best suited to each toolchain:

    Gatsby

  • Blog
  • Landing Pages
  • Any other website with static content
  • Next

  • Social Media-like Apps
  • Forum-like Apps
  • Real time interactive Apps
  • Apps that require syncing content between client in real time
  • create-react-app

  • Learning
  • Thanks for reading!

    Kumar Harsh
    May 24, 2020
    SDE Intern | Student Mentor | Tech Writer | MERN | Mobile | Gratitude 🍁
    Read More

    Read 0 times

    Comment!