There are hundreds of libraries and frameworks to choose from in the Jamstack world. As there are some benefits and drawbacks to selecting some over others. And in this article, we'll compare the benefits of using next.js and create-react-app (CRA) with strapi as a headless CMS.
Strapi is an open-source, self-hosting, and database agnostic headless API with a fully customizable CMS front-end. With strapi, it's never been easier to create a customizable and performance content API.
It saves weeks of API development time and allows for easy long-term content management via a user-friendly administration panel, and guess what? It's completely free!!!
Next.js is a react framework for creating single-page Javascript applications (SPA). It supports static export, pre-rendering, and other useful features such as automated building size optimization, quicker developer compilation, and a preview mode.
Next.js provides the finest developer experience with all of the capabilities you need for production, like hybrid static and server rendering, TypeScript support, smart bundling, route prefetching, and more.
Create React App (CRA) is an officially approved method for developing single-page React apps. It provides a contemporary build setup that requires minimal configuration. With CRA, It is not necessary to install or set up technologies such as Webpack or Babel. They are preset and hidden so that you may concentrate on the code.
When choosing any software library or framework, developer experience is usually taken into account. When I talk about developer experience, I mean how developers complete a task. Developers tend to favor libraries or frameworks that are fun and easy to use. This is the main reason we have leading libraries and frameworks today.
In the React world, Next.js has become a popular framework for "getting to the point." As I know, React fans take Next.js and enjoy working with it in their projects.
Next.js is built on top of React to make development easier. Next.js takes a little getting used to, but even developers new to the front-end world can quickly start. So, it comes out that there is a different experience building a project with Next.js and React.
The next title will go deeper into the details of comparing both next.js + strapi and CRA + strapi while discussing their performance, ease of use, what it is like to initially launch a project, learn these technologies, and their documentation.
The process of starting a new react app with strapi as its back-end is fairly simple. To begin, run the following command to create a new react app:
npx create-react-app project-name
The next step is to create a new strapi project, which we can do by running the following command:
1 npx create-strapi-app project-name
2 # OR
3 yarn create strapi-app project-name
Running the command above will prompt questions about the type of installation, whether you want to use a template and other options, but you can answer them all according to your preferences.
Finally, an HTTP client is required to make requests to the strapi API. We can use Axios for tasks like this one:
1 npm install axios
2 # OR
3 yarn add axios
Using next.js and strapi
The procedure for creating a new strapi application using next.js as its front-end is identical to the one we followed for React above, with the exception that you'll need to build a next.js app first, which you can accomplish by running:
npx create-next-app project-name
This section will compare both based on the following criteria for us to have a thorough understanding:
So let's get right into it.
Speed and easiness of coding:
Next.js was crafted with a ton of built-in functionality to make creating react apps easier and faster.
For example, next.js comes with its file-system based routing, which means you won't have to install react-router
or configure routes and import components for different routes; all you have to do is create a pages
folder in your project root directory, and the routes will be generated automatically for all the .js
files in this folder, which is ideal for a strapi application because you'll most likely be working with routable objects.
Performance
Compared to react, apps developed using Next.js are lightning-fast due to their static-site and server-side rendering features. Furthermore, server-side rendering is advantageous for strapi applications because it lets you load data before a component is mounted into view, which improves speed.
SEO Optimization
Strapi is undoubtedly one of the best headless CMS for SEO available, owing to its versatility and content clustering function.
However, while deciding whether to use CRA or next.js for better SEO optimization, next.js comes out on top because React applications do not have support for server-side rendering and will serve a complete application from a single entry point. Search engines crawling this website will only be able to view material from that single initial page.
Data Fetching
To fetch asynchronous data in react, you'll need to go through an extra step of installing additional libraries, such as the react-async
library.
Although you can choose to fetch these types of data directly in the useEffect()
hook, doing so has its limitations, as it will be more complex to handle asynchronous UI states.
Next.js, on the other hand, next.js comes with its data fetching technique, with support for both static-site and server-side created apps.
This is advantageous for strapi since you will undoubtedly want the material from your API to be loaded as quickly and efficiently as possible.
Additional Features
Some other advantages Next.js has over CRA include:
Some other advantages of using next.js with strapi includes:
While next.js has been favored in working with strapi throughout this article, you'll most likely need to know how create-react-app works before learning how to work with next.js. In contrast, some of the benefits of using CRA with strapi include:
In conclusion, Next.js tends to have more features and tools for working behind the scenes like, when SEO matters or when building a landing page or building websites, Next.js is very fast. In contrast, creating a React app has more resources to work on your web or mobile application's front-end or build a gated application.
My name is Fagbuyiro David, a software developer and technical writer. i like sharing my experience as a developer with others.