Giving a Client-Side React Blog Real SEO Without Server-Side Rendering
· 10 min read
A while back I pasted a link to one of my blog posts into a group chat, and the little preview card that came up had nothing to do with the post. It showed my name and the same one-line description that sits on every other page of the site, as if I'd shared my homepage instead of an article. The link worked fine when anyone tapped it, but to whatever was drawing that preview, every post on my blog looked exactly the same.
That is the catch with a client-side React app, and a blog built on Create React App walks right into it. Every route you visit is served the same index.html, with a single hardcoded title and a single meta description baked in at build time. The real title, the post body, the cover image, none of it exists in the page until the JavaScript bundle loads and React renders everything in the browser. A person never notices, because by the time they're reading, React has long since filled the page in. But anything that reads the raw HTML and doesn't run the JavaScript sees that empty shell and stops there.
And it bites in two separate ways. The link-preview bots behind X, LinkedIn, Slack, WhatsApp and Facebook don't run your JavaScript at all, so every link you share gets the same card no matter which post it points to. Google is a softer version of the same problem: it does render JavaScript before indexing, but on its own schedule and not always reliably, so counting on it to eventually find your real titles and content is a bet you'd rather not have to make.
What I didn't want to do was rewrite the blog to fix this. So here's how I gave a client-side React app proper SEO without moving it to server-side rendering: a small build step that writes a real HTML page per route, plus a sitemap and an RSS feed generated from the same source.
The standard advice when a React app has no SEO is to render it on the server, usually by moving to Next.js or something like it that ships real HTML for every request. For a lot of apps that's the right call, and if I were starting this site from scratch today I'd probably start there.
The thing is, my site already exists. It's built on Create React App, deployed to Netlify, and it does its job. The blog is the only part that needs search engines and preview cards to see real content, and the posts themselves are Markdown files that hardly change once they're out. Rewriting a working portfolio to solve one problem on one section of it is a lot of risk for not much return. A prerendering service would have worked too, but that's a runtime dependency and a recurring bill for something I can just as easily do once, at build time.
So what I actually needed was narrow: hand crawlers a real <head> and a copy of the content for each page, and otherwise leave the live app exactly as it is for everyone who shows up with a browser.
My posts already get turned into JSON when the site builds. A script, build-posts.mjs, reads the Markdown in content/published/, runs it through remark and rehype to render the HTML, and writes out an index of every post plus a file for each one. That happens before the React build, in the prebuild step:
{
"prebuild": "node scripts/build-posts.mjs --production",
"build": "react-scripts build",
"postbuild": "node scripts/seo-pages.mjs"
}
The SEO work hangs off postbuild. By the time it runs, Create React App has already produced build/index.html, and a second script, seo-pages.mjs, treats that file as a template. For every route it writes a copy with three things changed: the page's own <title>, its meta tags, and a <noscript> block holding a plain-HTML version of the content.
The upshot is that a request for a post no longer lands on the generic build/index.html. It lands on build/seo/blog/<slug>.html, which is the same app shell carrying this post's real head:
<title>Giving a Client-Side React Blog Real SEO… | David Emaye</title>
<meta name="description" content="A Create React App blog serves the same index.html…"/>
<link rel="canonical" href="https://davidemaye.com/blog/client-side-react-blog-seo"/>
<meta property="og:title" content="Giving a Client-Side React Blog Real SEO…"/>
<meta property="og:description" content="A Create React App blog…"/>
<meta property="og:image" content="https://davidemaye.com/images/writing/…cover.webp"/>
<meta property="og:type" content="article"/>
and, further down, the content itself sitting inside <noscript>:
<noscript>
<main><article>
<h1>Giving a Client-Side React Blog Real SEO Without Server-Side Rendering</h1>
<p><time datetime="2025-03-18">March 18, 2025</time> · 9 min read</p>
</article></main>
</noscript>
A crawler that doesn't run JavaScript now has everything it could want: the right title, a description, the Open Graph and Twitter tags for a proper preview card, the structured data, and the article text itself. A browser with JavaScript skips the <noscript> block completely and runs the app the way it always did.
There's a snag in that last part. The app sets its own <title> and meta tags once it loads, through react-helmet-async, so if the pre-rendered page already carries a <title> and React goes and adds another, you can end up with two of everything.
react-helmet-async handles this cleanly as long as you meet it halfway. Any tag it means to manage carries a data-rh="true" attribute, and when the app hydrates it replaces the matching tags instead of appending new ones. So in the pre-rendered file I mark exactly the tags the app is also going to render, and leave the crawler-only extras unmarked:
const meta = (attr, key, content, managed = true) =>
`<meta ${attr}="${key}" content="${escapeHtml(content)}"${managed ? ' data-rh="true"' : ""}/>`;
The tags React owns get data-rh; the few Open Graph and Twitter fields that exist only for crawlers, because the app never bothers setting them, don't. Once the app loads, the managed tags are taken over in place and nothing is left duplicated.
The homepage needs one extra bit of care. It carries site-identity tags, the og:site_name and a WebSite block of JSON-LD that tell Google the name to show in results, and those belong to the homepage alone, not to every post. I tag them data-site-identity in the template and strip them back out when I'm generating any page that isn't the homepage:
template
.replace(/<meta[^>]*data-site-identity[^>]*>/g, "")
.replace(/<script[^>]*data-site-identity[^>]*>[\s\S]*?<\/script>/g, "");
Writing the files is only half of it. The other half is making sure a request for /blog/<slug> actually gets build/seo/blog/<slug>.html and not the default shell.
On Netlify that comes down to a _redirects file. The rule every React single-page app already has is the catch-all that sends everything to index.html so client-side routing can take it from there:
/* /index.html 200
The move is to slip the blog's rules in ahead of that catch-all, and to use a 200 rather than a 301. A 200 is a rewrite, not a redirect: the URL in the browser stays /blog/<slug>, but Netlify quietly serves the pre-rendered file's contents. The script generates these and splices them in before the catch-all:
/blog /seo/blog.html 200
/blog/client-side-react-blog-seo /seo/blog/client-side-react-blog-seo.html 200
# …one line per post…
/* /index.html 200
Posts I first published somewhere else are the exception. They show up on my blog, but their canonical home is on dev.to or wherever they originally ran, so their /blog/<slug> sends a genuine 301 straight to the original instead of serving a duplicate of someone else's page on my domain.
Once a script already has every post's metadata in hand, a sitemap and an RSS feed are only a few more lines in the same step, and generating them from that same source is what keeps them from drifting out of sync with what's actually published.
For the sitemap I list the site's main pages and every on-site post, and I only attach a lastmod where I actually have a date I trust. Stamping today's date onto every page on every build just teaches Google to ignore the field, so the pages with no reliable date don't get one. The posts I host elsewhere stay out of the sitemap altogether, since they're not meant to be indexed on my domain in the first place.
The feed is a plain RSS 2.0 file built the same way, newest post first, and I point at it from every page with an autodiscovery link in the head so a reader's feed app can find it without being told where it is:
<link rel="alternate" type="application/rss+xml" title="David Emaye" href="/feed.xml"/>
While you're in there, one more thing is worth adding: links between related posts, written into that same <noscript> block. The live app already shows a "keep reading" section at the bottom of each post, but React renders that, so a crawler that skips the JavaScript never sees a single one of those links. Dropping a few related-post links into the pre-rendered HTML gives crawlers real paths from one post to the next, which is how you want them stumbling onto the posts a brand-new sitemap entry hasn't walked them to yet. I keep those links pointed at on-site posts only, so each one leads somewhere worth indexing.
The awkward thing about this bug is how quiet it is, because everything looks perfect in a browser. So I check it the way a crawler would, with the JavaScript left off:
curl -s https://davidemaye.com/blog/client-side-react-blog-seo | grep -i '<title>'
If that comes back with the post's title rather than "David Emaye", the rewrite and the pre-rendered head are both doing their job. After that, the browser's view-source, not the inspector, which shows you the rendered DOM and hides the whole point, confirms the <noscript> content and the Open Graph tags are really in the raw HTML. A link-preview debugger from any of the social platforms confirms the card, and in Google Search Console the URL Inspection tool shows you the page exactly as Googlebot fetched it, which is the test that actually counts.
I should be clear about what this is and isn't. It isn't server-side rendering. The <noscript> block is a fallback copy of the content for machines that won't run JavaScript; real visitors still get the page the usual way, from React rendering in the browser. What the build step buys me is that the raw HTML tells the truth about each page before a line of my JavaScript runs, and that's all a crawler or a preview bot ever needed.
It's a good trade when your situation looks like mine, which is a content section that's basically static once it's published, living inside a client-side app you'd rather not rewrite, on a host that can rewrite URLs to static files. The price is a build script you now own and have to keep working, and the honest limit is that it only holds up while things stay simple. The day your pages start depending on per-request data, or on interactivity the pre-rendered copy can't stand in for, you've outgrown this and should move to something that renders on the server or generates the pages properly.
For a blog bolted onto a React portfolio, though, it closed the gap completely. The preview card in that group chat shows the right title now, and the posts turn up in search as themselves instead of as one more copy of my homepage.