Written by Brian Hulela
Updated at 20 Jun 2025, 16:44
5 min read
Photo by Justin Morgan on Unsplash
Search Engine Optimization (SEO) is a critical factor in web development. If your app isn’t optimized for search engines, it won’t rank well, and organic traffic will suffer.
If you’ve built a React app, you might have noticed SEO challenges — especially when it comes to search engine crawlers not indexing your content properly. That’s because React, by default, renders everything on the client side (CSR). This means search engines don’t immediately see the full page content, making it harder for them to rank your pages.
The solution? Server-Side Rendering (SSR) with Next.js.
Migrating from React to Next.js can significantly improve SEO, thanks to SSR and other built-in optimizations. This guide will walk you through how SEO works in React, why SSR helps, and how to optimize your Next.js app for search engines.
React apps are single-page applications (SPAs), meaning they rely heavily on client-side rendering (CSR). Here’s what happens when a search engine bot tries to index a CSR-based React page:
The bot requests a URL.
The server responds with a basic HTML file (usually just <div id="root"></div>
).
The bot has to wait for JavaScript to load and execute before seeing any content.
Some crawlers (like Google’s) can process JavaScript, but not all search engines do this efficiently. This can lead to:
Pages not being indexed properly.
Lower rankings due to poor page speed.
Poor previews in social shares (since metadata is dynamically injected).
This is where Next.js and SSR come into play.
Unlike React’s default CSR approach, Next.js supports Server-Side Rendering (SSR) and Static Site Generation (SSG), both of which improve SEO.
With SSR, Next.js renders the page on the server before sending it to the browser. This means:
The bot receives fully rendered HTML immediately.
The page is indexed properly without waiting for JavaScript.
Faster initial load times improve SEO rankings.
To enable SSR in Next.js, you use getServerSideProps()
:
export async function getServerSideProps() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return {
props: { data },
};
}
export default function Page({ data }) {
return <div>{data.title}</div>;
}
If your content doesn’t change frequently, you can use Static Site Generation (SSG) instead of SSR. SSG pre-builds pages at build time, making them even faster for users and search engines.
export async function getStaticProps() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return {
props: { data },
revalidate: 10, // Re-generate page every 10 seconds
};
}
SSG is great for blogs, marketing pages, and product listings that don’t change often.
Once you’ve moved to Next.js, there are several ways to further optimize SEO:
SEO relies heavily on proper meta tags for titles, descriptions, and social sharing. Next.js makes this easy with the next/head
component:
import Head from "next/head";
export default function Page() {
return (
<>
<Head>
<title>Best SEO Practices for Next.js</title>
<meta name="description" content="Learn how to optimize your Next.js site for SEO." />
<meta property="og:title" content="Best SEO Practices for Next.js" />
<meta property="og:description" content="Learn how to optimize your Next.js site for SEO." />
<meta property="og:image" content="/seo-guide.png" />
</Head>
<h1>Optimizing SEO in Next.js</h1>
</>
);
}
This ensures that:
Search engines display the correct page title and description.
Social media previews show the correct image and metadata.
Next.js automatically optimizes URLs. But you should still structure them properly:
Use descriptive URLs: /blog/how-to-improve-seo
instead of /blog/1234
.
Avoid unnecessary query parameters in public URLs.
Define dynamic SEO-friendly routes with Next.js:
import { useRouter } from "next/router";
export default function BlogPost({ post }) {
return <h1>{post.title}</h1>;
}
export async function getStaticPaths() {
const res = await fetch("https://api.example.com/posts");
const posts = await res.json();
const paths = posts.map((post) => ({
params: { id: post.id.toString() },
}));
return { paths, fallback: false };
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://api.example.com/posts/${params.id}`);
const post = await res.json();
return { props: { post } };
}
Google prioritizes fast-loading pages. Next.js helps by optimizing images, code splitting, and lazy loading.
Use next/image
for optimized images:
import Image from "next/image";
<Image src="/hero.jpg" width={800} height={600} alt="SEO Best Practices" />;
Enable automatic static optimization by using SSG where possible.
Use next/script
for async/defer loading of third-party scripts (e.g., analytics).
Migrating from React to Next.js with SSR can dramatically improve your site’s SEO. By ensuring search engines get fully rendered pages, optimizing metadata, and improving performance, Next.js helps your site rank better and load faster.