AEO Guide — Next.js
AEO for Next.js
Next.js makes AEO easy — you have full control over the rendered HTML, structured data, and headers. The App Router's Metadata API handles half the work. Here's the complete setup for AI search visibility.
What is AEO for Next.js? AEO for Next.js involves adding JSON-LD structured data via the generateMetadata API or script tags, serving llms.txt from the public directory, configuring robots.ts for AI crawlers, and using semantic HTML elements (main, article, section) in your components. Next.js 13+ App Router makes this straightforward with server components and Metadata Route handlers.
The 5 AEO fixes for Next.js
Step 1
Add FAQPage JSON-LD via script tag
In any server component, render a <script type="application/ld+json"> with your FAQ data. Next.js will include it in the static HTML, which is what AI crawlers parse.
export default function Page() {
const jsonLd = {
'@context': 'https://schema.org',
'@type': 'FAQPage',
mainEntity: faqs.map(f => ({
'@type': 'Question',
name: f.q,
acceptedAnswer: { '@type': 'Answer', text: f.a },
})),
}
return (
<>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
{/* Your FAQ UI */}
</>
)
}Step 2
Drop llms.txt into /public
Next.js serves anything in /public at the site root. Create public/llms.txt with your site info, key pages, and system prompt — it'll be live at yoursite.com/llms.txt instantly.
Step 3
Configure robots.ts for AI bots
Use the Metadata Route handler for robots.txt — it generates the file at build time with full type safety.
// app/robots.ts
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return {
rules: [
{ userAgent: 'GPTBot', allow: '/' },
{ userAgent: 'ClaudeBot', allow: '/' },
{ userAgent: 'PerplexityBot', allow: '/' },
{ userAgent: 'Google-Extended', allow: '/' },
{ userAgent: 'Amazonbot', allow: '/' },
{ userAgent: '*', allow: '/' },
],
sitemap: 'https://yoursite.com/sitemap.xml',
}
}Step 4
Use semantic HTML in components
Wrap your layout in <main>, blog posts in <article>, and section groupings in <section>. The App Router's layout.tsx is a natural place to add the outer <main>.
// app/(marketing)/layout.tsx
export default function MarketingLayout({ children }) {
return (
<>
<MarketingHeader />
<main>{children}</main>
<Footer />
</>
)
}Step 5
Add Quick Answer blocks to posts
In your blog template, add a styled .quick-answer div right after the H1. Pull the summary from MDX frontmatter or a CMS field.
Why Next.js needs AEO
- Next.js renders to HTML that AI crawlers can read — unlike client-rendered SPAs
- The Metadata API makes canonical URLs, Open Graph, and structured data trivial to add per route
- Serving llms.txt from /public means zero infra changes
- robots.ts catches typos at build time (unlike a static robots.txt)
- Server components default to HTML-first output — great for AEO
Next.js AEO FAQ
Do I need ISR or SSG for AEO on Next.js?
Either works. What matters is that the HTML includes your structured data and semantic tags at the time the AI crawler requests it. Server components and SSG both satisfy this; pure client-side rendering does not.
Where should I put llms.txt in a Next.js project?
In the /public directory at your project root. Next.js serves it at yoursite.com/llms.txt automatically. No API route needed.
Should I use generateMetadata or a script tag for JSON-LD?
Use a <script type="application/ld+json"> tag inside your component. generateMetadata is for meta tags and Open Graph, not structured data.
Does Next.js support the <article> tag?
Yes — all HTML5 semantic tags work in JSX. Just write <article>, <main>, <section>, <aside>, <header>, <footer> directly in your components.
Check your Next.js site's AEO score
Free scan. See which AEO checks your Next.js site passes and fails in seconds.