What is Create React App?

Create React App is an officially supported way to create single-page React applications.

Again, for the purposes of this post, we are paying attention to the term “single-page.”

SSR vs. CSR

Next.js is one way that you can leverage React to support server-side rendering (SSR). Likewise, Create React App is one way that you can leverage React to support client-side rendering (CSR).

There are other frameworks out there when it comes to either choice, but what we are really comparing in this post is how each rendering strategy impacts web application performance. We just happen to be using two of the more popular frameworks out there to make that comparison.

These diagrams postulate that SSR can deliver HTML to the browser faster than CSR can, so let’s make that our hypothesis: a web application built with SSR is more performant than one built with CSR.

Test parameters

The best way to test our hypothesis is by building two applications with identical functionality and UI. We want it to mimic a real-world application as much as possible, so we will set a few parameters.

The application must:

Fetch data from an API

Render a non-trivial amount of content

Carry some JavaScript weight

Mobile matters

Software developers are typically spoiled with high-powered computers paired with blazingly fast office networks; we do not always experience our applications the same way our users do.

With that in mind, when optimizing for performance, it is important to consider both network and CPU limitations. Mobile devices generally have less processing power, so heavy JavaScript file parsing and expensive rendering can degrade performance.

Fortunately, Chrome provides a dev tool called Lighthouse, which makes it easy for us to step into the shoes of our users and understand their experience. You can find this under the Audits tab in Chrome DevTools.

We will use the exact settings displayed above:

Mobile device

Applied Fast 3G, 4x CPU Slowdown

Clear storage

Geography matters

If you live in Northern California and you are on servers living in AWS us-west-1 (N. California) all day, you are not experiencing your application the same way as your users in other parts of the United States, nor other parts of the world.

So, for the purposes of this test, the demo apps and the API were deployed to Sydney, Australia (specifically, Zeit’s syd1 region). The client’s browser will be accessing the applications from Boulder, CO, USA.

The distance between Boulder and Sydney is 8,318 mi (13,386 km).

Look at what that means for data fetching between these two applications.

getInitialProps is a special function that Next.js uses to populate the initial data for a page in Next.js. You can learn more about fetching data with Next.js in their docs.

So what’s with all these components, and why are you using Moment.js?

Going back to our original test parameters, we are trying to test with an application that at least somewhat resembles one we would ship to production. The ThemeProvider, PrimaryNav, etc. all come from a UI component library called Mineral UI.

We are also pulling in Moment.js because it is a larger dependency that adds some JavaScript weight and also some additional processing that needs to occur when rendering the component tree.

The actual libraries that we’re using are not important; the point is to get a little closer to the weight of a normal application without taking the time to build all of that in its entirety.

Results

Here are the Lighthouse results for a full page load on each application.

This audit identifies the time at which the user feels that the primary content of the page is visible.

Lighthouse also helps us visualize these differences:

Create React App (CSR)Next.js (SSR)

Do the visuals above look familiar? They should because they mimic the diagrams included in the Hypothesis section, where we postulated that SSR can deliver HTML to the browser faster than CSR. Based on these results, it can!

LogRocket is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.

In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also instruments the DOM to record the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.

6 Replies to “Next.js vs. Create React App: Whose apps are more…”

One thing that I believe needs to be clarified is that Next.js takes advantage of isomorphic/universal rendering. When an app is loaded for the first time, it’s loaded via SSR. Afterwards, CSR kicks in, giving you the best of both worlds.

The linked Walmart Labs article is excellent but it’s important to remember it’s from 2017, and they call out synchronous SSR as a bottleneck with renderToString. This is no longer the case with React 16 and the enhancements that Fiber brought.