Skip to main content
Best Practices
SEO for React eCommerce SPA

SEO for React eCommerce SPA

React is super popular for eCommerce these days. Single-page applications (SPA) are typically the starting point due it their awesomeness. React SPA is however not awesome for SEO and time to first meaningful render. This is where server-side rendering (SSR) with Next.JS comes in. Frontend performance is super-important according to the ecommerce SEO checklist so you need to have fast APIs. GraphQL done properly could help your performance that you should verify with profiling and benchmarking. For eCommerce SEO the good old best practice still applies like title and h1 tag usage.

Single Page Application SEO

A single-page application (SPA) is good for many things, but it is not great for SEO. Mainly React SPA does not have the concept of pages or different URLs. As each page URL is dynamically loaded with Javascript voodoo. It gives a very fast user experience, but search engines typically do not understand anything. The result is that the pages will simply not be indexed - i.e. be invisible to Google and other search engines.

SPA in React typically also has a larger overhead on the first load as there are many packages and dependencies to be loaded before any content is rendered. This is mostly a user experience issue with a long initial time to meaningful render. They have to wait to see the products - loading... Google penalizes webshops that are slow - but in this case, it would not be indexed anyway.

React SSR with NextJS to the Rescue

From a user experience perspective, the super-fast loading of ecommerce pages that you typically get from SPA is something we want. Very much actually. But we do not like the potential slow time to first meaningful render and we need our webshop to be indexed by search engines.

The solution to this is surprisingly simple: let’s render the first request on the server. Next.JS is a great framework to hook up with your React eCommerce SPA. With Next.JS and SSR you basically render the first page on the server and send plain HTML to the browser. Normal SPA mode takes over after this. But you get super-fast time to first meaningful render and search engines love it as they can understand the HTML and index it.

Oh, the bonus: search engines can index all products and pages. This is because SSR also renders any incoming URL request as static HTML. Yay.

API Performance with GraphQL

Product information management is the core of any eCommerce application. You want the shop managers to easily create and modify rich product descriptions in their PIM interface and have their webshop automagically being always up to date. The rich product information is typically delivered to your webshop via an API - this is what we call headless ecommerce.

In my experience, a REST API slows your ecommerce application down. This is due to architectural design limitations mainly. With a REST API, you typically have to send one request to fetch a list of resources, i.e. products. Then send one request for each of the product resources to fetch the product information. Worst case a list of 10 products could lead to 11 API calls! This is horrible in terms of performance.

GraphQL is designed to solve exactly this. One query to fetch the product data you need and only this. With GraphQL you have a simple to understand query language to fetch a deep tree of content. Since you can choose exactly what data to transfer in each query you also optimize data transfer time.

Fast GraphQL API Performance is Good for SEO

It is no secret that Google is favoring eCommerce, or any website if they are fast. Since the API performance is directly linked to your SERP ranking (your placement in the search engine result page) you need a fast ecommerce API. This is where benchmarking and profiling come in. Remember always to keep an eye on your application performance including the API layer.

A good tool to check your website speed is the Google Pagespeed Insight. That gives you a good indication of how Google sees your webshop in terms of performance when indexing. Of course, this is not a benchmark or scaleout testing tool but delivers what we need to check here for SEO and performance.

Good old SEO Best Practice

Of course, building a webshop on React means that you still have to comply with the good old and ever-evolving SEO best practice. In the end, you are sending HTML pages to the browser and the search engine indexing bots.

There are plenty of resources out there on this topic, but remember things like:

  • Title tags with main keywords first
  • H1 tags for titles, h2 for subtitles, etc with main keywords first
  • URLs in plain text with keywords
  • Canonical link tag
  • Meta tags including OG share tags that use real content like product title, image, description, and price
  • Paragraph text that repeats your keywords
  • Link text with keywords of the page it links to
  • The image needs alt text with good keywords
  • Image and file names should be descriptive and include the main keyword(s)

That should get you started with some proper SEO for your eCommerce. Check out our ecommerce SEO checklist for more tips.

You can check out our React eCommerce boilerplate for an example of how we do this. Don´t worry it is fully open source and MIT licensed.