Serve structured JSON for AI agents/crawlers while keeping normal Next.js behavior for regular users.
Modern AI agents such as ChatGPT/OpenAI crawlers, Claude/Anthropic bots, Perplexity, and similar automation clients usually do not need full browser-ready HTML, JS bundles, and client hydration payloads. nxpage lets you serve a lightweight JSON representation for these agent requests, while normal users still get the standard Next.js HTML app.
This gives practical benefits:
- Faster agent response delivery (smaller payloads)
- Lower network egress and transfer cost
- Reduced CPU usage for bot traffic paths
- Cleaner extraction path for crawlers and AI systems
Depending on page size and app complexity, this can reduce transfer volume by up to ~99% for bot-targeted responses.
The fastest way to get up and running is with create-nxpage-app. It scaffolds a new Next.js project with NxPage already wired up — server config, build script, and route filters all included out of the box.
npx create-nxpage-app myapp
cd myappThis creates a new project with a ready-to-use server.ts (or server.js) that calls createNxPageServer with a starter config. Open it to customise your route patterns before building:
// server.ts (generated by create-nxpage-app)
import { createNxPageServer } from "nxpage";
createNxPageServer({
port: Number(process.env.PORT ?? 3000),
includeRoutePatterns: ["/docs/**", "/blog/**"],
blockRoutePatterns: ["/docs/internal/**"],
});Any includeRoutePatterns and blockRoutePatterns you set here are automatically used during the manifest build step as well — you only define your route config once.
npm run buildThe build script runs both steps back to back automatically:
next build— produces the standard HTML output in.next/nxpage build— reads the HTML output and generates lightweight JSON pages in.next/nxpage-pages/, using the same route config passed tocreateNxPageServer
No separate manifest step needed. The config drives everything.
npm startThat's it. Your app now serves:
- Regular users → standard Next.js HTML (unchanged behaviour)
- AI agents & crawlers → compact JSON from
.next/nxpage-pages/for matched routes
myapp/
├── app/ # your Next.js pages and routes
├── server.ts # NxPage server entry point (edit route patterns here)
├── package.json # build script runs next build + nxpage build together
└── ...
newupdate/
├── packages/
│ ├── nxpage/
│ └── create-nxpage-app/
├── pnpm-workspace.yaml
├── tsconfig.base.json
└── package.json
packages/nxpage— runtime server + manifest builder for bot-oriented JSON responses.packages/create-nxpage-app— CLI scaffolder for a Next.js app with NxPage setup.
cd nxpage
pnpm installIf pnpm is not available on your machine:
npm i -g pnpmpnpm -r run buildpnpm --filter nxpage run build
pnpm --filter create-nxpage-app run buildNotes: Source is written in TypeScript. Build output is emitted as CommonJS (
.cjs) in each packagedistfolder.
- Build your Next app (human HTML build).
- Run NxPage manifest build (bot JSON build).
- Start NxPage server.
- AI agents receive JSON for allowed routes; humans continue receiving normal HTML.
| Build | Command | Output |
|---|---|---|
| Human build | next build |
.next/* — normal HTML flow |
| Bot build | nxpage build |
.next/nxpage-pages/* — bot/agent JSON flow |
You can control which routes are included/excluded with includeRoutePatterns and blockRoutePatterns.
A CLI scaffolder that sets up a new Next.js app with NxPage pre-configured.
cd newupdate/packages/create-nxpage-app
npm install
npm run buildnpm i nxpagecreateNxPageServer(options?)generateNxPageManifest(options?)
NxPage uses the same Next.js build as input, then creates two different response outputs:
- Human output (HTML build) — Standard Next.js pages generated by
next build, served normally for human/browser traffic. - Bot output (JSON build) — NxPage reads generated HTML files and creates per-route JSON pages for AI agents.
So in practice you get:
- Normal Next HTML for users
- Lightweight JSON pages for AI agents (ChatGPT/OpenAI, Claude, Perplexity, and others)
# 1) Normal Next.js build (HTML output)
next build
# 2) NxPage bot build (JSON output)
nxpage buildAfter this, your app has both artifacts:
- Next HTML output in
.next/* - NxPage JSON output in
.next/nxpage-pages/*
Create a custom server that:
- Detects bot/agent traffic
- Serves prebuilt NxPage JSON manifest for matching routes
- Falls back to normal Next request handling for other cases
| Option | Type | Default | Description |
|---|---|---|---|
port |
number |
3000 |
Port to listen on |
manifestPath |
string |
.next/nxpage-pages/server/app |
Path to JSON manifest |
isBot |
(req) => boolean |
built-in | Custom bot detection function |
includeRoutePatterns |
(string | RegExp)[] |
— | Only these routes are eligible for JSON serving |
blockRoutePatterns |
(string | RegExp)[] |
— | Always excludes matched routes |
- If
includeRoutePatternsis provided, only matching routes are eligible. blockRoutePatternsalways excludes matched routes.- Final rule: route must pass include filter (if any) and not match block filter.
import { createNxPageServer } from "nxpage";
createNxPageServer({
port: 3000,
includeRoutePatterns: ["/docs/**", "/blog/**"],
blockRoutePatterns: ["/docs/internal/**"],
});Scans Next build output HTML and generates JSON manifest files consumed by the server.
| Option | Type | Default | Description |
|---|---|---|---|
distDir |
string |
.next |
Next.js build output directory |
manifestPath |
string |
— | Override output path for the manifest |
includeRoutePatterns |
(string | RegExp)[] |
— | Routes to include |
blockRoutePatterns |
(string | RegExp)[] |
— | Routes to exclude |
import { generateNxPageManifest } from "nxpage";
await generateNxPageManifest({
distDir: ".next",
includeRoutePatterns: ["/docs/**"],
blockRoutePatterns: ["/docs/internal/**"],
});The package includes a CLI command:
nxpage buildThis runs manifest generation with default options.
next buildimport { generateNxPageManifest } from "nxpage";
await generateNxPageManifest({
distDir: ".next",
includeRoutePatterns: ["/docs/**", "/blog/**"],
blockRoutePatterns: ["/docs/internal/**"],
});import { createNxPageServer } from "nxpage";
createNxPageServer({
port: Number(process.env.PORT ?? 3000),
includeRoutePatterns: ["/docs/**", "/blog/**"],
blockRoutePatterns: ["/docs/internal/**"],
});- AI agents receive NxPage JSON for allowed routes.
- Blocked or non-included routes fall back to normal Next.js handling.
- Human users continue to receive standard HTML pages.
cd newupdate/packages/nxpage
npm install
npm run build