Manage SEO in JavaScript applications
When developing any single-page application or a website that uses JavaScript to fetch content from APIs, you need to think carefully about search engine optimization.
Indexing by search engines
Content fetched from Delivery API via client-side AJAX requests will not be indexed by Google, Bing, and other search engines. By default, the API doesn’t allow it. Most engines apart from Google don't even try to index JavaScript calls. If you need the API responses to be indexable, discuss this requirement with our support team. The best practice is to make sure search engines are served fully rendered HTML with all the content you wish to be indexed. This can be achieved in several ways, each with a different trade-off among performance, complexity, and cost. In general, you have three options: Below you will find a brief introduction to each approach and links to additional resources. There is no single best solution; you always need to consider the specific requirements of your project.Server-side rendering
Server-side rendering is the practice of using a server to render content and serve the rendered HTML on the initial page load. The full JavaScript bundle loads later and subsequent requests are handled by the client. This solves the SEO problem and can improve perceived performance by reducing the initial load time of your single-page app. These kinds of apps are sometimes called isomorphic applications because their code can run on both client and server. On the downside, server-side rendering increases the complexity of your application and can hinder performance in some situations, for example, when the server is under a heavy load. All major front-end frameworks support server-side rendering or provide dedicated server-side rendering frameworks:- React: check out Next.js
.
- Angular: see Angular SSR
.
- Vue: check out Nuxt.js
.
Prerendering
Rather than using a web server to compile HTML on the fly per request, prerendering simply generates static HTML files for specific routes at build time. The advantage is that setting up prerendering is simpler and it allows you to keep your frontend as a static site without the need for a node server. Any single-page application can be prerendered at build time using a prerendering tool or plugin appropriate to your build system, or by using a hosted prerendering service (see below). For React specifically, there’s react-snapStatic site generators
Static site generators are tools that take your source code, assets, content from APIs, and so on, and generate your website as a collection of static files. You can host the static files anywhere and SEO is not a problem. If your website doesn't require authentication or display real-time or user-specific data, consider using a static site generator.- Jamstack.org
provides an overview of all static site generators.
- Next.js
is an open-source React framework.
Testing
You can use the URL inspection tool by Google
to see the index status of your website.