DEV Community

Muhammad Zeeshan
Muhammad Zeeshan

Posted on

What Googlebot Actually Gets From a Next.js Page

A Next.js app can look finished in Chrome and still be a weak page in search. You click around, the product name appears, and the URL updates cleanly. A crawler does not get that fully hydrated session. It requests a URL, looks at the response, and, if it renders JavaScript at all, it does so later and with limits.

That gap is the whole job behind JavaScript SEO for modern websites. The question is not whether your framework is "good for SEO." It is whether the HTML for a given URL already contains the main content, the links, and the metadata, or whether those only appear after a client-side fetch.

Render the content on the server, then confirm it without opening DevTools

App Router server components, and the Pages Router's getServerSideProps or getStaticProps, put the important text in the first response. That is the path you want for anything you hope to rank: product pages, docs, blog posts, and marketing landing pages.

The pattern that still causes trouble is a client component that starts empty and fills itself in useEffect. A crawler, a disabled-JavaScript check, or a delayed render queue may only see a loading state.

// The first HTML has no product name.
'use client'

import { useEffect, useState } from 'react'

export default function ProductPage() {
  const [product, setProduct] = useState(null)

  useEffect(() => {
    fetch('/api/products/sku-104')
      .then((res) => res.json())
      .then(setProduct)
  }, [])

  if (!product) return <p>Loading…</p>
  return <h1>{product.name}</h1>
}
Enter fullscreen mode Exit fullscreen mode
// The first HTML already contains the heading.
import { notFound } from 'next/navigation'

export default async function ProductPage() {
  const product = await getProduct('sku-104')
  if (!product) notFound()
  return <h1>{product.name}</h1>
}
Enter fullscreen mode Exit fullscreen mode

The second version has another advantage: notFound() sends a real 404. A client-only empty state that still returns HTTP 200 is a soft 404, and search engines have to guess whether the URL is a page or a miss.

Do not trust the Elements panel when you test this. Use curl, "View Page Source," or the HTML tab in Search Console's URL Inspection. If the title, H1, and main paragraph are missing there, they are not reliably in the document you want indexed.

Put metadata in generateMetadata (App Router) or next/head (Pages Router) so the canonical URL and title are also in that first response.

import type { Metadata } from 'next'

export async function generateMetadata({
  params,
}: {
  params: Promise<{ slug: string }>
}): Promise<Metadata> {
  const { slug } = await params
  const product = await getProduct(slug)
  if (!product) return { title: 'Not found', robots: { index: false } }

  return {
    title: product.name,
    description: product.summary,
    alternates: {
      canonical: `https://example.com/products/${product.slug}`,
    },
  }
}
Enter fullscreen mode Exit fullscreen mode

Client-side navigation is fine if each URL also works as a fresh request. Hash routes (/#/products/sku-104) and content that only appears after a "Load more" click, with no paginated URL, are much harder to discover.

Keep the URL space boring

Once rendering works, the next failure is often volume. Preview deployments, search-result pages, sort and filter query strings, and session parameters can create thousands of addresses that say almost nothing new. That is how crawl budget and indexation issues show up on a JavaScript site.

Crawl budget is the capacity a search engine spends fetching your host. If much of it goes to ?color=, ?sort=, or temporary preview URLs, fewer of the pages you care about get crawled and stored. Indexation is separate: a crawled URL can still be left out if it looks thin, duplicate, or contradictory.

Pick one trailing-slash rule in next.config and stick to it. Keep preview and draft routes out of the index. If a filter combination is useful enough to rank, give it a stable, canonical URL and link to it. If it is only a UI state, leave it out of the sitemap and consider a noindex or a canonical back to the clean listing. Internal links should point to that canonical form, not to a leftover query string from the last click.

Do not block the files Google needs to render the page

XML sitemaps and robots.txt still do the coordination work, and they are easy to get wrong in a compiled app.

The classic Next.js mistake is a blanket Disallow: /_next/. That path holds the CSS and JavaScript the app needs. If you block it, you may be hiding the files required to render the page you wanted Google to see. Block what should not be crawled (/api/, draft or preview paths, internal search), and leave the assets alone.

import type { MetadataRoute } from 'next'

export default function robots(): MetadataRoute.Robots {
  return {
    rules: {
      userAgent: '*',
      allow: '/',
      disallow: ['/api/', '/draft/'],
    },
    sitemap: 'https://example.com/sitemap.xml',
  }
}
Enter fullscreen mode Exit fullscreen mode

The sitemap should list only canonical, indexable URLs that return 200. Generated routes, pagination that should not be indexed, and anything that redirects or carries a noindex directive do not belong there. In the App Router, app/sitemap.ts can build that list from the same data as the site.

import type { MetadataRoute } from 'next'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const products = await getIndexableProducts()

  return [
    {
      url: 'https://example.com',
      lastModified: new Date(),
    },
    ...products.map((product) => ({
      url: `https://example.com/products/${product.slug}`,
      lastModified: product.updatedAt,
    })),
  ]
}
Enter fullscreen mode Exit fullscreen mode

After you ship a change, fetch robots.txt and sitemap.xml yourself. Confirm the sitemap is referenced, the important URLs are present, and nothing useful is disallowed by accident.

Fix Core Web Vitals on the template, not page by page

Rendering and discovery get you into the index. Google also treats Core Web Vitals as part of its page experience signals. The useful way to think about Core Web Vitals for service and ecommerce sites is at the template level: the header, the hero or product image, the fonts, and the third-party scripts are shared, so one fix often moves many URLs.

Largest Contentful Paint is often a late hero image or a font that delays the first heading. Interaction to Next Paint suffers when a large client bundle or a heavy tag manager competes with the main thread. Cumulative Layout Shift shows up when images or ads have no reserved size, or when a font swap restyles the heading after the first paint.

next/image and next/font exist to make those problems harder to create. Mark the LCP image with priority, give it real dimensions or a sized container, and be careful with third-party scripts that inject banners or chat widgets above the fold.

import Image from 'next/image'

export function ProductHero({ product }) {
  return (
    <Image
      src={product.hero}
      alt={product.imageAlt}
      width={1200}
      height={630}
      priority
    />
  )
}
Enter fullscreen mode Exit fullscreen mode

Measure with field data in Search Console and CrUX when you have enough traffic, and use Lighthouse or local traces to debug a template. A lab score on quiet staging will not tell you what a shopper's phone does with your tag manager enabled.

A short test order before you ship

Before you call a template done, run a boring sequence:

  1. Request the URL with curl or "View Page Source" and confirm the H1, main paragraph, and important links are in the HTML.
  2. Check the status code. Missing documents should be 404, not a 200 with a "not found" message painted in by JavaScript.
  3. Open robots.txt and make sure /_next/ and other render assets are not blocked. Confirm the sitemap lists only the canonical URLs you want indexed.
  4. Click a few internal links, then reload each destination as a fresh request so you are not only testing client-side routing.
  5. Review the LCP image, font loading, and third-party scripts, then check Search Console for coverage and Core Web Vitals once the change is live.

None of this requires a new SEO tool. It requires treating the first HTML response, the status code, and the shared template as part of the product. If those are right, the JavaScript can enhance the page. If they are wrong, the polished UI is mainly for people who already found you.

Top comments (0)