---
title: SEO Optimization for Client Side Rendered Next.js Apps
description: Learn how to serve crawler bots, render rich previews and optimize for SEO for your client side rendered Next.js app.
url: https://rishi.app/blog/seo-optimization-for-client-side-rendered-nextjs-apps
author: Rishi Raj Jain
published_at: 2024-01-02T03:44:08.209Z
updated_at: 2026-10-14T22:26:37.602Z
---

# SEO Optimization for Client Side Rendered Next.js Apps

When I was designing and building at [wellowise](https://wellowise.com) a Client Side Rendered Angular 7 app, the biggest concern was Search Engine Optimization for the business. Why? Because it helps crawler bots such as Google to know the content and index the page, and show rich previews when sharing the page link on Social Media (such as WhatsApp, Telegram, etc.). Similarly,

### Client Side Rendered Next.js apps lack Search Engine Optimization and Rich Previews

So I set out for solving the case of dynamic rewrites with [Vercel](https://vercel.com) and [Next.js](https://nextjs.org), where I planned to identify the request of crawler bots and rewrite a given URL which takes care of creating rich previews and emitting out HTML containing server-side content, if bots are crawling any page that starts with `/posts/` in my app. Let's get started.

## Configuring Regex for identify crawler bot request

Here's a regex that one can use to identify requests with `User-Agent` header of a crawler bot.

```js
// File: next.config.js

const allowedBots = '.*(bot|telegram|baidu|bing|yandex|iframely|whatsapp|facebook).*';
```

## Configuring Next.js Config for Detecting Crawler Bots

Update the `next.config.*` of your app to contain the following condition for a rewrite:

```js
// File: next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  // ...
  async rewrites() {
    return [
      // ...
      {
        // From where the bots would be redirected to crawl the page
        destination: 'https://my-og.url/posts/:match*',
          
        // The condition which redirects the bots to the destination above
        has: [{ key: 'user-agent', type: 'header', value: allowedBots }],
          
        // The path regex where the condition above is ran for
        source: '/posts/:match*'
      }
    ];
  },
}

module.exports = nextConfig;
```

and we're done! With this set up in place, each request that'd come to your app's `/posts/:slug` pages from the crawler bots, the app would [proxy](https://rishi.app/blog/what-is-proxying.md) and serve the content from the url: `https://my-og.url/posts/:slug`.

## Configuring Upstream OG URL

By now, we've configured crawler bot requests to `https://my-og.url/posts/:slug`. The next step in creating social preview is to configure the `upstream-og.url` to dynamically send out [all SEO Meta Tags](https://dev.to/reeshee/seo-meta-tags-for-your-articles-55h) required for a great social preview when the link is shared and informational content for the crawlers to index.

## Example

[https://github.com/heyxyz/hey/blob/main/apps/web/next.config.js#L65-L73](https://github.com/heyxyz/hey/blob/main/apps/web/next.config.js#L65-L73)

---

This is the Markdown version of https://rishi.app/blog/seo-optimization-for-client-side-rendered-nextjs-apps. Every page on this site is listed with a summary at https://rishi.app/sitemap.md.
