Serving llms.txt in Next.js: Static File vs. Route Handler
Next.js makes serving a spec-compliant /llms.txt straightforward whether you use Static Export, Pages Router, or the App Router. Validate your draft in the editor above first so your headings, blockquote summary, and token budget stay clean.
Method 1: Static File in public/llms.txt (Fastest)
Download llms.txt from the editor above and save it directly to public/llms.txt. Next.js automatically serves it at https://yourdomain.com/llms.txt without any routing configuration.
Method 2: Dynamic App Router Handler (app/llms.txt/route.ts)
If your documentation or blog updates frequently from MDX or a CMS, serve /llms.txt dynamically with caching headers:
export const revalidate = 3600;
export async function GET() {
const body = [
'# Your Project Name',
'',
'> Concise summary of your Next.js documentation and product.',
'',
'## Documentation',
'- [Quickstart](https://yourdomain.com/docs/quickstart): Install and deploy in 5 minutes.',
].join('\n');
return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}