Why Next.js is the right technology for SEO
SEO has become increasingly important and is now one of the most crucial aspects to focus on when building a website. That's because SEO directly drives good rankings on Google, and therefore brings more people to your website. In recent years React, Gatsby, Vue and Angular have taken over, but applications built with these technologies tend to have poor SEO. This is where Next.js comes in: the right technology for SEO!
Let's look at what you need to know about SEO, how to handle it in Next.js and why adopting DatoCMS could be the best approach for you.
SEO has become increasingly important and is now one of the most crucial aspects to focus on when building a website. That's because SEO directly drives good rankings on Google, and therefore brings more people to your website. In recent years React, Gatsby, Vue and Angular have taken over, but applications built with these technologies tend to have poor SEO. This is where Next.js comes in: the right technology for SEO!
Let's look at what you need to know about SEO, how to handle it in Next.js and why adopting DatoCMS could be the best approach for you.
What is SEO?
SEO stands for Search Engine Optimization and covers all the strategies used to push a web page higher in search engine results. In other words, the better your SEO, the easier it is for people to find your website and click on it. SEO can therefore also be defined as the process of increasing the quality and quantity of traffic to a website through clicks from organic search. Organic search refers to the part of search results where rankings cannot be bought. SEO optimization therefore aims to improve your organic ranking.
As you can easily imagine, SEO is key to getting as many people as possible to visit your website. When using a search engine, people tend to click on the top results it returns, and the better your site's SEO, the higher your site will appear. This puts your products, services or content in the spotlight. And more visitors means more sales and customers.
At the same time, dealing with SEO is not trivial. The most popular search engines are constantly evolving and change their algorithms very often. So a good SEO ranking doesn't last forever, and it's up to you to keep your site competitive in terms of SEO ranking.
Let's now look at which technologies to adopt to achieve great SEO.
Why Next.js is the technology built for SEO
Next.js is a JavaScript web framework for building statically generated and server-rendered React applications. When you use React to build SPAs (Single Page Applications), what you get is a single HTML file containing several JavaScript files. When you navigate between the pages of an SPA, the page doesn't actually change: it's the browser that mounts the requested view on the fly using JavaScript. Navigation between pages is simulated on the client side and no request is made to the server.
In other words, the pages that make up the website don't exist until the browser renders them. As a result, a crawler has no easy way to discover them, because technically they don't exist. This is a huge SEO problem, because it makes SPA pages very hard for search engines to index.
Unlike client-side rendered applications, server-side rendered applications have one file per page. This means every page exists before the browser renders it. In other words, crawlers can index them all effortlessly and treat them differently based on their content, which is known in advance. Next.js lets you achieve this result while using React as your front-end technology. So it offers all the benefits of React without neglecting SEO. In fact, giving developers the ability to achieve excellent SEO performance is one of the pillars of Next.js. Not by chance, the official Next.js website offers an entire guide to SEO. That's why Next.js is the right technology for SEO.
Let's now learn how to use Next.js to handle SEO properly.
Everything you need to know about the Next.js Head component
HTML alone is not enough to meaningfully describe the content of a web page. That's why search engines try to understand it by analyzing the metadata stored in HTML <meta> tags. As explained in Google's documentation, these tags are essential for SEO.
Meta tags must be placed in the <head> section of an HTML page, which is why Next.js comes with a built-in <Head> component. Let's see it in action in the following example:
Thanks to the Next.js <Head> component, you can use <meta> tags just as if you were building an HTML page. Meta tags can include titles, descriptions, information about the social pages related to the website, as well as any data for the Open Graph protocol.
Once the <meta> tags are wrapped in the <Head> component, Next.js picks up the defined metadata and automatically places it in the best possible position in the HTML page during server-side rendering.
Having this metadata in the server-generated HTML file avoids the SEO problems described earlier that affect client-side rendered applications built with React, Gatsby, Vue or Angular.
The main drawback of Head in Next.js
The solution Next.js offers is technically excellent and flexible, but that doesn't change the fact that defining metadata correctly takes time. Plus, this metadata should be easy to update.
The problem is that it lives in the <Head> component of the JavaScript or TypeScript file that represents the web page. This means that to update a page's metadata you have to change its code accordingly, build the whole application and deploy it to the server again.
This is undoubtedly a cumbersome process that should be avoided as much as possible. Nobody wants to spend time on it, especially since SEO evolves very quickly and is usually handled by marketers or SEO specialists who may not know how to code.
Luckily, there's DatoCMS!
Why Cantiere Creativo chooses DatoCMS
DatoCMS is a headless CMS that gives you everything you need to manage your content through a simple web interface anyone can use. Specifically, DatoCMS is a Software-as-a-Service that differs from WordPress because it's a back-end platform that exposes all its features through APIs, which can be called from any front-end technology. DatoCMS lets you decouple content management from content presentation.
DatoCMS is especially useful for SEO because it lets you define and edit the metadata SEO needs in its advanced web interface, usable by anyone, even non-technical users. Specifically, you can use the `react-datocms` package to fetch SEO metadata from DatoCMS already encoded in the correct HTML meta tags and wrap it in the Next.js <Head> component, as shown in the following example taken from a page of the official documentation:
This separates where SEO metadata is defined and stored from where it's actually used. So you can use DatoCMS to update your pages' SEO without touching the code, as explained in detail here. This way, there's no need to rebuild and redeploy the website whenever you want to update SEO information, avoiding all the problems covered in the previous section.
At the same time, describing a web page's content for SEO is as important as it is tedious. Fortunately, DatoCMS comes with the YoastSEO plugin. This powerful tool generates useful SEO and readability metrics in real time while you edit content in DatoCMS. The YoastSEO plugin also automatically detects potential SEO issues and suggests useful improvements. SEO becomes a piece of cake!
This is just one of the many reasons we use DatoCMS in our projects. Explore all our articles about DatoCMS here or read our getting started guides.
Conclusion
In this article we looked at what SEO is, why it matters so much and what options Next.js offers to handle it. First, we covered everything you need to understand SEO. Then we analyzed the difference between client-side and server-side rendering, and why Next.js is the right technology for SEO.
Finally, we explored the Next.js <Head> component and how to use it to define the meta tags search engines need to understand the content of your website's pages. Still, handling SEO with this component alone can get complicated. Fortunately, DatoCMS makes SEO accessible to everyone, giving you everything you need.
Thanks for reading! We hope you found this article useful. Feel free to contact us here with any questions, comments or suggestions.