Course contentsShow
← Web Development
Lesson 1881 of 2,98234. Metadata and SEOFree lesson

Dynamic Rendering and Bot Detection

Serving different content to bots versus users, including implementation patterns and caveats.

Dynamic Rendering and Bot Detection

You'll learn how to serve optimized HTML to search bots while keeping interactive JavaScript for real users—and when this trade-off makes sense.

What Is Dynamic Rendering?

Dynamic rendering is a technique where your server detects whether the visitor is a search engine bot or a human user, then serves different versions accordingly. Bots get pre-rendered, static HTML (easy to crawl), while users get your full client-side JavaScript application.

Think of it like a museum with two entrances: scholars get a detailed catalog (static HTML), while tourists get an interactive audio guide (your SPA). Both see the same content, just packaged differently.

Implementation Pattern

The core workflow:

  1. Detect the user agent in your server middleware
  2. Check against known bot signatures (Googlebot, Bingbot, etc.)
  3. If bot: serve pre-rendered HTML (often using a headless browser like Puppeteer)
  4. If user: serve your normal SPA bundle
// Pseudocode - concept only
if (isBotUserAgent(request.headers['user-agent'])) {
  return prerenderedHTML;
} else {
  return spaBundle;
}

Important Caveats

  • Not Google's preferred solution: Google recommends SSR or static pre-rendering instead, as dynamic rendering adds complexity
  • Cloaking risk: Serving drastically different content to bots versus users violates search engine guidelines—content must be equivalent
  • Maintenance overhead: You're maintaining two rendering pipelines
  • User-agent detection isn't foolproof: Bots can be spoofed, and new crawlers appear regularly

When to Consider It

Dynamic rendering works as a temporary bridge when you have a legacy SPA that can't easily adopt SSR, but need better SEO immediately.

Key Takeaway: Dynamic rendering detects bots and serves them pre-rendered HTML while users get the JavaScript app—it's a pragmatic compromise, not a best practice, and should be replaced with proper SSR or static generation when possible.