← All posts

Astro vs Next.js for SEO: what differs on a client site

Astro and Next.js both send Google finished HTML. They differ in what stays static, where the head tags live, and which mistake each one makes easy.

QueryScope team · · 10 min read · astro nextjs seo developers

Astro and Next.js both send Google finished HTML, so neither one ranks better because of the framework. Astro prerenders every page unless you opt one out, and ships no JavaScript unless you ask for it. Next.js prerenders a page when it can, and stops once the page reads something only a request has. For SEO, the choice comes down to which defaults you want and which mistakes you want to be hard to make.

This is written for a studio picking a framework for a client site. Every claim about either framework below is from its own docs, linked at the end.

TL;DR:

  • Both put the title, description and body text in the HTML response. Google does not need to run JavaScript to read either.
  • Astro is static until you opt a page out. Next.js is static until a page reads a cookie, a header or the query string.
  • In Astro you write the head tags yourself, in one component. In Next.js you export a metadata object and the framework writes them.
  • Next.js generates the sitemap and robots.txt from code files. Astro uses an integration for the sitemap and a plain file for robots.txt.
  • Each has one sitemap default that dates every page to the last build. Fix it in both.

Which one does Google read more easily?

Neither. Both return a complete HTML page, and that is the part that matters. Astro's docs describe its default output mode as "Prerender all your pages by default". In Next.js, pages and layouts are Server Components by default, and Client Components are prerendered to HTML too.

Google can render JavaScript, but it does so in a second step. Its docs say "Googlebot queues pages for both crawling and rendering", and still advise that "server-side or pre-rendering is still a great idea because it makes your website faster for users and crawlers, and not all bots can run JavaScript". Both frameworks follow that advice out of the box, so a page built with either one is readable by every crawler, including the ones that do not run scripts.

The gap opens after the HTML. Astro's docs say it renders "every UI component to just HTML & CSS, stripping out all client-side JavaScript automatically", and a component only gets JavaScript when you add a client:* directive to it. In Next.js the browser still gets JavaScript: the docs say it "is used to hydrate Client Components and make the application interactive", and they advise keeping 'use client' on the interactive parts only to keep that bundle small. On a content site the difference shows up in load time, not in what Google reads.

What stays static, and what quietly stops being static?

In Astro a page stays prerendered until you write export const prerender = false at the top of it and add an adapter. Nothing else moves a page to the server, so you always know which pages are static.

In Next.js the switch can happen without a line that says so. The caching docs list cookies, headers, searchParams and params as things that need a request. A page that starts reading one of them can no longer be built fully ahead of time.

That matters for the head tags. The Next.js docs say that for dynamically rendered pages it "streams metadata separately", and that the tags are appended to the <body> once they resolve. Google is fine with that: the docs say they verified it for bots that run JavaScript, and name Googlebot. Crawlers that only read HTML are detected by user agent and get the tags in the <head> before the response starts. Prerendered pages do not stream at all. So on a marketing page, keep it prerendered and the question never comes up.

Where do the title, description and canonical live?

In Astro you write them as HTML, in one head component that every layout uses. The docs give the canonical line: new URL(Astro.url.pathname, Astro.site). Astro.site comes from the site value in your config and is undefined until you set it.

---
// src/components/BaseHead.astro
const { title, description } = Astro.props;
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
---

<title>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={canonicalURL} />

In Next.js you export an object and the framework prints the tags. Set metadataBase once in the root layout, then each page can give a relative canonical.

// app/pricing/page.tsx
import type { Metadata } from 'next'

export const metadata: Metadata = {
  title: 'Pricing',
  description: 'Three plans, by number of sites.',
  alternates: { canonical: '/pricing' },
}

Two rules from the Next.js docs are worth knowing before a build fails on them. The metadata export and generateMetadata "are only supported in Server Components", so a page marked 'use client' cannot set its own title. And a relative URL in a metadata field with no metadataBase "will cause a build error".

Astro has no such guard by default. A page that forgets its description builds without complaint, unless you make the field required in the content collection schema. Astro SEO shows that schema, and Next.js SEO covers the metadata object in full.

How does each one handle the sitemap and robots.txt?

Next.js treats both as code. A file at app/sitemap.ts exports a function that returns the list of URLs, and app/robots.ts returns the rules. Both live next to your routes and can read the same data your pages do.

Astro uses the @astrojs/sitemap integration, which writes sitemap-index.xml and sitemap-0.xml into the build output, and a plain public/robots.txt file you write by hand. One limit from its docs: the integration "cannot generate sitemap entries for dynamic routes in SSR mode", so pages you render on demand have to be added yourself.

Both make the same mistake easy. The Next.js docs' own example sets lastModified: new Date(), and the Astro integration's lastmod option sets one date for the whole site. Either way every URL claims to have changed at the last build. Google's docs say it uses lastmod only "if it's consistently and verifiably" accurate, so a sitemap like that teaches Google to ignore the field. In both frameworks, feed the date from when the content changed. How Google uses lastmod goes through the cases.

Try it

Point an SEO agent at your own site, not just an essay about one.

QueryScope holds the plan for your site, reads your real Search Console, and hands the coding agent you already have one change at a time to rank for the searches you decided to win. From $49/month, everything included.

What about trailing slashes?

Next.js picks for you. Its docs say "By default Next.js will redirect URLs with trailing slashes to their counterpart without a trailing slash." One URL per page, with no setup.

Astro leaves it open. Its trailingSlash option defaults to 'ignore', described as "Match URLs regardless of whether a trailing "/" exists". Both forms can be linked and both can answer, so set the option to one form and make the canonical and the sitemap use the same one.

Astro vs Next.js for SEO, side by side

  • Default rendering. Astro: every page prerendered. Next.js: prerendered when the page allows it.
  • What makes a page dynamic. Astro: export const prerender = false plus an adapter. Next.js: reading cookies, headers or the query string.
  • JavaScript sent to the browser. Astro: none unless a component has a client:* directive. Next.js: enough to hydrate the Client Components.
  • Title and description. Astro: HTML you write in a head component. Next.js: a metadata export, server only.
  • Canonical. Astro: new URL(Astro.url.pathname, Astro.site). Next.js: alternates.canonical with metadataBase.
  • Sitemap. Astro: the @astrojs/sitemap integration. Next.js: app/sitemap.ts.
  • robots.txt. Astro: a file in public/. Next.js: app/robots.ts.
  • Trailing slash default. Astro: both forms match. Next.js: redirects to no trailing slash.

So which should a studio pick for a client site?

Pick on what the site is, because the SEO outcome is the same when both are set up properly. A brochure site, a blog or a docs site with little interactivity suits Astro: everything is static and the pages are light. A site with accounts, a dashboard or pages that change per visitor suits Next.js, where the marketing pages and the app share one codebase.

Then watch for the mistake your pick makes easy. In Astro that is two URLs for one page and a head tag nobody required. In Next.js it is a marketing page that turned dynamic without anyone deciding it should.

Neither framework answers the question a client asks a month after launch: which page do we change next, and did the last change work? That answer is in the client's Search Console, not in the build. If you build and run client sites in a repo, SEO for web agencies that build client sites in code shows how QueryScope handles it: a plan per client site, one change at a time from your coding agent, and a dated record of every change.

Sources

  • Astro docs, Configuration reference (output and its 'static' default; site; trailingSlash and its 'ignore' default).
  • Astro docs, Islands architecture (components rendered to HTML and CSS with client-side JavaScript stripped; client:* directives).
  • Astro docs, On-demand rendering (export const prerender = false; an adapter is needed).
  • Astro docs, API reference (Astro.site, Astro.url and the canonical URL example).
  • Astro docs, @astrojs/sitemap (the generated files; no entries for dynamic routes in SSR mode; the site-wide lastmod option).
  • Next.js docs, Server and Client Components (layouts and pages are Server Components by default; Client Components are prerendered to HTML; JavaScript hydrates Client Components; keeping the client bundle small).
  • Next.js docs, Metadata and OG images (Server Components only; streaming metadata on dynamically rendered pages; prerendered pages do not stream).
  • Next.js docs, generateMetadata (metadataBase, alternates.canonical, the build error; streamed tags appended to the body; Googlebot and HTML-limited bots).
  • Next.js docs, sitemap.xml and robots.txt (the file conventions; the new Date() example).
  • Next.js docs, trailingSlash (the default redirect).
  • Next.js docs, Caching (cookies, headers, searchParams and params need a request).
  • Google Search Central, JavaScript SEO basics (pages queued for crawling and rendering; server-side or pre-rendering still advised).
  • Google Search Central, Build and submit a sitemap (lastmod used when consistently and verifiably accurate).

Try it

Put an SEO agent in your editor.

Ask your coding agent what to work on. QueryScope reads your real Search Console, holds the searches you decided to win, and hands back one move at a time with the proof it worked. From $49/month, everything included. 1, 3 or 10 sites.