Next.js vs. Create React App: Whose apps are more performant?
Tags: createreactapp, nextjs, react
Published: 2019-07-08 20:22:38

---
title: Next.js vs. Create React App: Whose apps are more performant?
published: true
tags: create-react-app,nextjs,react
canonical_url: https://blog.logrocket.com/next-js-vs-create-react-app/
---

![](https://thepracticaldev.s3.amazonaws.com/i/ek6mz3tdc0m7prtctmt2.jpg)

## Introduction

What are the performance differences between Next.js and Create React App? Let’s unpack that question with some data, but first, we need to understand what exactly we are comparing here.

### What is Next.js?

Next.js is a React framework built by [Zeit](https://zeit.co), and according to [nextjs.org](https://nextjs.org/):

> _With Next.js, server rendering React applications has never been easier, no matter where your data is coming from._

Next.js also supports static exporting, but for the purposes of this post, we are focused on that “server rendering” capability mentioned above.

### [![LogRocket Free Trial Banner](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/f760c-1gpjapknnuyhu8esa3z0jga.png?resize=1200%2C280&ssl=1)](https://logrocket.com/signup/)

### What is Create React App?

According to its [Getting Started](https://facebook.github.io/create-react-app/docs/getting-started) page:

> _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.

## The experiment

Let’s start our experiment with a question: **Does SSR improve application performance?**

### Hypothesis

Walmart Labs published a great post titled, “[The Benefits of Server Side Rendering Over Client Side Rendering](https://medium.com/walmartlabs/the-benefits-of-server-side-rendering-over-client-side-rendering-5d07ff2cefe8).” They also provide some excellent diagrams that demonstrate the fundamental difference between SSR vs. CSR performance.

![Server-Side Rendering Infographic](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/ssr-explanation.png?resize=800%2C570&ssl=1)

![Client-Side Rendering Infographic](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/csr-explanation.png?resize=800%2C564&ssl=1)

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.

![Audits Tab Contents In Chrome DevTools](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/audits-tab-chrome-devtools.png?resize=1322%2C1306&ssl=1)

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](https://zeit.co/docs/v2/platform/regions-and-providers/)). 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).

![Distance Between Sydney And Boulder](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/boulder-sydney-difference.png?resize=730%2C725&ssl=1)

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

![CSR Data Fetching](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/csr-data-fetching.png?resize=741%2C661&ssl=1)<figcaption>CSR</figcaption>

![SSR Data Fetching](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/ssr-data-fretching.png?resize=741%2C661&ssl=1)<figcaption>SSR</figcaption>

### Two applications, one API

The code for the two apps is available in my [GitHub](https://github.com/goldenshun/nextjs-cra).

Here are the applications:

- [Create React App](https://nextjs-cra.goldenshun.now.sh/)
- [Next.js](https://nextjs-cra.goldenshun.now.sh/nextjs)

All of the code is in a monorepo:

- `/cra` contains the Create React App version of the application
- `/nextjs` contains the Next.js version
- `/api` contains a mock API that both applications use

The UI appears identical:

![CSR User Interface](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/cra-ui.png?resize=730%2C581&ssl=1)<figcaption>CSR</figcaption>

![SSR User Interface](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/nextjs-ui.png?resize=730%2C586&ssl=1)<figcaption>SSR</figcaption>

And the JSX is nearly identical:

```jsx
// Create React App
<ThemeProvider>
  <div>
    <Text as="h1">Create React App</Text>
    <PrimaryNav align="left" maxItemWidth="20rem">
      <NavItem href="/" selected>Create React App</NavItem>
      <NavItem href="/nextjs">Next.js</NavItem>
    </PrimaryNav>
    <Table
      data={users}
      rowKey="id"
      title="Users"
      hideTitle />
  </div>
</ThemeProvider>
```
```jsx
// Next.js
<ThemeProvider>
  <div>
    <Text as="h1">Next.js</Text>
    <PrimaryNav align="left" maxItemWidth="20rem">
      <NavItem href="/">Create React App</NavItem>
      <NavItem href="/nextjs" selected>Next.js</NavItem>
    </PrimaryNav>
    <Table
      data={users}
      rowKey="id"
      title="Users"
      hideTitle />
  </div>
</ThemeProvider>
```
We will get to what the `ThemeProvider` and other components are in a moment.

The code differs in how the data is fetched from the API, however:

```jsx
// Create React App
// This all executes in the browser
const  = useState([]);
useEffect(() => {
  const fetchData = async () => {
    const resp = await axios.get('/api/data');
    const users = resp.data.map(user => {
      return {
        id: user.id,
        FirstName: user.FirstName,
        DateOfBirth: moment(user.DateOfBirth).format('MMMM Do YYYY'),
      }
    });
    setUsers(users);
  };
  fetchData();
}, []);
```
```jsx
// Next.js
// This all executes on the server on first load
Index.getInitialProps = async({ req }) => {
  const resp = await axios.get(`http://${req.headers.host}/api/data`);
  const users = resp.data.map(user => {
    return {
      id: user.id,
      FirstName: user.FirstName,
      DateOfBirth: moment(user.DateOfBirth).format('MMMM Do YYYY'),
    }
  });
  return { users };
}
```
`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](https://nextjs.org/docs#fetching-data-and-component-lifecycle).

### 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](https://mineral-ui.com/).

We are also pulling in [Moment.js](https://momentjs.com/) 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.

![Create React App Lighthouse Results](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/cra-lighthouse-results.png?resize=753%2C1058&ssl=1)<figcaption>Create React App (CSR) results</figcaption>

![Next.js Lighthouse Results](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/nextjs-lighthouse-results.png?resize=751%2C1012&ssl=1)<figcaption>Next.js (SSR) results</figcaption>

To understand the details of these metrics, read the [Lighthouse Scoring Guide](https://developers.google.com/web/tools/lighthouse/v3/scoring).

One of the more notable differences for our purposes is the First Meaningful Paint.

- **CRA:** 6.5s
- **Next.js:** 0.8s

According to Google’s [First Meaningful Paint](https://developers.google.com/web/tools/lighthouse/audits/first-meaningful-paint) docs:

> _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 First Meaningful Paint](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/cra-first-meaningful-paint.png?resize=891%2C141&ssl=1)<figcaption>Create React App (CSR)</figcaption>

![Next.js First Meaningful Paint](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2019/06/nextjs-first-meaningful-paint.png?resize=905%2C143&ssl=1)<figcaption>Next.js (SSR)</figcaption>

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!

To view the Lighthouse results yourself:

1. Download the files for [CRA](https://www.dropbox.com/s/g6ezatrz1iushgo/lighthouse-cra?dl=0) and [Next.js](https://www.dropbox.com/s/i71x8in664eb95t/lighthouse-nextjs?dl=0)
2. Open [https://googlechrome.github.io/lighthouse/viewer/](https://googlechrome.github.io/lighthouse/viewer/) in Chrome
3. Drag the downloaded files into the Lighthouse Viewer in Chrome

## Conclusion

We opened our experiment with a question: **Does SSR improve application performance?**

We built two nearly identical applications, one that uses client-side rendering with Create React App and one that uses server-side rendering with Next.js.

The Lighthouse results from our simulations showed better metrics in the Next.js application in all significant categories, especially First Meaningful Paint (87.69 percent decrease), First Contentful Paint (87.69 percent decrease) and Time to Interactive (27.69 percent decrease).

* * *

## Plug: [LogRocket](https://logrocket.com/signup/), a DVR for web apps

[![LogRocket Dashboard Free Trial Banner](https://i2.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/1d0cd-1s_rmyo6nbrasp-xtvbaxfg.png?resize=1200%2C677&ssl=1)](https://logrocket.com/signup/)

[LogRocket](https://logrocket.com/signup/) 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.

[Try it for free](https://logrocket.com/signup/).
* * *

The post [Next.js vs. Create React App: Whose apps are more performant?](https://blog.logrocket.com/next-js-vs-create-react-app/) appeared first on [LogRocket Blog](https://blog.logrocket.com).