Blog

5 React best practices for SEO

Although React is one of the most popular frameworks on the market, it can be quite difficult to get a site that uses it indexed.

In this article, we will look at how to create a site suited to search engine optimization. You will learn the main obstacles that prevent React from being SEO-friendly and become familiar with best practices to make your web application attractive to Google.

 

How Google’s crawlers work

To solve the SEO problem of React applications, we need to understand the how Google crawlers work and the common issues React faces.

Google uses crawlers to index websites. These crawlers explore the pages of your site to find new ones. When creating a website, you can choose the pages you want crawlers to visit by listing them in the Sitemap. To avoid overloading your site with crawler requests, and to save your "crawl budget", you can also ask not to crawl certain pages.

The next step carried out by Google's crawlers is indexing. During this process, a Google crawler analyzes a web page's content to understand what it's about: the results of this process are stored in Google's index.

Because web page indexing is automated, it is important to structure and format content so that it is understandable by a machine.

The final step includes the serving and ranking processes. When a user performs a search, Google consults its index to find the most relevant results.

So what's the problem with React web applications?

How Google’s crawlers work

Why is it hard to optimize React for SEO?

Developers must identify the issues encountered by search engines that try to crawl and index React pages.

Let’s take a closer look: what makes React SEO difficult and what can developers do to overcome this challenge.

1. Empty content

We know React applications rely on JavaScript, and they often run into issues with search engines. This is because React uses an application shell model by default. The initial HTML contains no meaningful content; a user (or a bot) must execute JavaScript to see the page’s content.

This approach means Googlebot detects an empty page on its first pass. To see the content, it must wait for the page to be rendered. This delays content indexing, especially when there are dozens (hundreds?) of pages.

2. Loading time and user experience

Fetching, parsing, and executing JavaScript takes time. In addition, JavaScript may need to make network calls to retrieve content, and the user may have to wait a while before they can view the requested information.

Google has defined a set of web metrics related to user experienceThey are used in its ranking criteria. A long loading time can affect the user experience score, causing Google to rank a site lower.

Load time and user experience

3. Metadata

The meta tags are useful: they allow Google and social networks to display titles, thumbnails, and descriptions for each page. To obtain this information, they rely on the page’s <head> tag. These sites therefore do not execute JavaScript for the target page.

React renders all content, including meta tags, on the client. Since the application shell is the same across the website/app, it can be difficult to tailor metadata for individual pages.

 

How to make your React website SEO-friendly?

4. Pre-rendering

Pre-rendering is a common approach to make an application suitable for search engines.

Pre-rendering is used when search bots cannot render your pages correctly. In that case, you can use special programs that intercept requests to your website and, if the request comes from a bot, send a cached static HTML version of your site. If the request comes from a user, the regular page is loaded.

Advantage
Prerendering programs can execute all types of modern JavaScript and convert them into static HTML. They support all the latest web features and require only minimal changes, if any.
Drawbacks
However, prerendering is not suitable for pages that display frequently changing data, and it can take a long time if the website is large and contains many pages. Additionally, you must rebuild your prerendered page every time you change its content. Finally, it can be costly.

5. Server-side rendering

If you plan to build a React web application, you should know the difference between client-side rendering and server-side rendering.

Client-side rendering means a browser and Googlebot receive empty HTML files or files with very little content. Then the JavaScript code downloads the content from the server and users see it on their screens.

In terms of SEO, client-side rendering is problematic, as Google’s crawlers receive no content or only limited content that they cannot index properly.

With server-side rendering, they receive HTML files containing all the content. Google’s crawlers can index the page correctly and rank it.

Server-side rendering is the simplest way to build an SEO-friendly React site.

 

Need help optimizing your React site for SEO? Find a React developer quickly by posting your project for free on Codeur.com !