# dvn skill invocation packet

Skill: public/prerender-for-agents
Status: STALE
Age: 600 seconds; source check: unavailable (SOURCE_UNAVAILABLE)

- devin-thomas/skills @ 4e48b69132901e3a6ec97b854d95d3d932ff01f6; verified 2026-12-02T21:31:47.472Z

Main source: prerender-for-agents/SKILL.md
Main Git blob: 29c898f81ef107e16a272c7fb7f377c537394e6f

---
name: prerender-for-agents
description: >-
  Prerender a client-rendered site (Vite, React, any SPA) into static HTML at
  build time so AI agents, crawlers and readers without JavaScript can read its
  content, with sitemap.xml, robots.txt, llms.txt and regression guards. Use
  when an agent or crawler sees an empty page or only the title, when the
  user wants a site's content readable by agents or search, or when adding
  llms.txt or a sitemap to an SPA.
---

# Prerender for agents

A **no-JS reader** (a ChatGPT or Claude web reader, a crawler, a link unfurler, `curl`) gets the HTML a server sends and runs no JavaScript. An SPA sends `<div id="root"></div>`, so the reader sees a title and nothing else. A **snapshot** fixes that at build time: crawl the built site in a real browser, save each page's rendered HTML as a static file, and let the app mount over it. People still get the app; readers get the content.

Found on JRPG Stat Lab (2026-10-23): a ChatGPT reader reached the site, read the title, got zero text and no sitemap. Portable copies of the five scripts from that fix are in [references/templates](references/templates); adapt them, do not rewrite them. The site origin, default title, route pattern and report-registry pattern at the top of `prerender-lib.mjs` are that site's examples: replace them with the project's own.

## 1. Measure the baseline

Done when you hold these numbers for the live URL (they are the before column of the final report):

```bash
curl -sL URL/some/page | sed -e 's/<script[^>]*>[^<]*<\/script>//g' -e 's/<[^>]*>/ /g' | tr -s ' \n' ' ' | wc -c
for p in /robots.txt /sitemap.xml /llms.txt /nope; do curl -s -o /dev/null -w "$p %{http_code} %{content_type}\n" URL$p; done
```

Tiny text (the stat lab gave 15 characters) confirms the defect. Crawler files answering `200 text/html`, and `/nope` answering 200, are **soft 404s**: the SPA catch-all (`/* /index.html 200`) swallows every missing file, so crawlers read "no sitemap".

## 2. Set the privacy border

The snapshot is exactly what a browser already shows a visitor, so it exposes nothing new. Hold that line:

- Prerender only public pages. Skip signed-in and per-user views.
- Deploy only the built directory. Databases, ROMs, source, raw data and source maps stay out; the `FORBIDDEN_FILE` pattern in `prerender-lib.mjs` makes the build fail if one lands in `dist/`.
- Confirm with the user before any public deploy, and state which files are new.

## 3. Build it

Each step ends when its check passes.

1. **Crawl and snapshot** (`prerender.mjs`, an npm `postbuild`). Serve the build with `vite preview`, crawl from `/` with Playwright following internal links, wait for the `<h1>` and for the loading placeholder to go, then keep `#root` HTML, `document.title` and the lede. Done when the script throws for any route declared in the app that no page links to.
2. **Write static files.** `/reports/x` becomes `reports/x.html` (Cloudflare Pages serves it at `/reports/x` and redirects `/reports/x.html` and `/reports/x/` there), `/` becomes `index.html`, and an untouched copy of the shell becomes `404.html`. Delete the catch-all redirect. Each page gets its own `<title>`, a meta description from its lede, and a canonical link. Done when an unknown path returns 404 with the app's not-found page.
3. **Mount over the snapshot, no flash.** Keep `createRoot`. Make the Suspense fallback the snapshot's HTML (`document.querySelector("main")?.innerHTML`, captured at module load), so a lazy route shows its page, not "Loading…", while its chunk downloads. Done when `browser-check.mjs` sees the text never disappear on a slow connection.
4. **Crawler files.** `sitemap.xml`, `robots.txt` and `llms.txt` (a one-line summary and a titled link per page), generated from the crawl so a new page needs no list entry. Done when `verify-site.mjs` finds every route in each.
5. **Guards**, three layers so the fix cannot quietly rot:
   - Unit tests for the pure helpers (`prerender-lib.test.mjs`, run by the project's test command), including a test that reads the app source and asserts routes, the fallback, the `postbuild` order and the absence of the catch-all.
   - `verify-site.mjs`: at the end of `postbuild` on `dist/` (a regression fails the build) and on a URL after deploy, checking text length, title, canonical, description, sitemap, robots, llms, content types, the 404 and forbidden files.
   - `browser-check.mjs`: no console errors, no overflow, charts present, no loading flash, desktop Chromium plus iPhone WebKit.
   Done when each guard has been seen to fail: run `verify-site.mjs` on the pre-fix live site (the stat lab: 64 problems) and delete a sitemap line from `dist/`.
6. **Deploy and verify live.** After the user approves, deploy, then run `verify-site.mjs URL` and `browser-check.mjs URL` plus the project's existing live checks (exports, layout), and compare with the step 1 baseline. Done when nothing regressed and the before/after numbers are on the record.

## 4. What it buys

Measured on JRPG Stat Lab: a report page went from 15 to 25,521 characters of text for a reader without JavaScript (6 tables, 9 sections); the sitemap, robots and llms.txt went from `200 text/html` to real files; `/nope` went from 200 to 404; every page got its own title instead of one site title.

Standard properties of static HTML, expected rather than measured here:

- **Agents.** Web readers and coding agents get the content in one request, with tables as real `<table>` markup; `llms.txt` and the sitemap give them a map.
- **Search and previews.** Indexers and link unfurlers read per-page titles, descriptions and canonical URLs from the HTML.
- **Speed and resilience.** Text paints with the first HTML, before the JavaScript bundle; the page stays readable when scripts are blocked, slow or fail.
- **Accessibility and archives.** Reader modes, screen-reader tools and web archives see the page.
- **Honest status codes.** Unknown paths are real 404s.
- **Cheap tests.** The site becomes checkable with `curl` in seconds, which is what makes the guards in step 5 possible.

## 5. Other ways to expose content to agents

The snapshot is the default: nothing new to author, and it cannot drift from the page. Reach for another form only for a stated reason.

| Form | Choose it when |
| --- | --- |
| Snapshot (this skill) | The page text is the content agents should read. |
| `llms.txt` only | You want a map and the pages are already server-rendered. |
| A `.md` or `.json` mirror per page | Agents need clean text or data without chart and layout markup. It is a second copy: generate it from the same data and test that it matches. |
| Server-side rendering | Content is per-request, or the app already runs a server. |

## 6. Gotchas

- `hydrateRoot` over a browser-captured snapshot fails (React error 418) on every page with a lazy route or adjacent text nodes: the snapshot lacks Suspense markers and `<!-- -->` text separators. Mount with `createRoot` and the fallback in step 3.
- `String.replace` with `$&` or `$1` in page text corrupts it; pass a replacer function.
- The snapshot is the desktop render. JS-chosen layouts (phone charts) take over after mount; the text is the same.
- Per-page titles come from the app's own code (`document.title`); the snapshot only records them.
- Cloudflare Pages behaviour was checked both in `wrangler pages dev dist` and live: `reports/x.html` answers at `/reports/x`, while `/reports/x.html` and `/reports/x/` return 308 to it. Another host may differ, so test its URLs before choosing the file layout.
- Check content types, not status codes: a catch-all makes every missing file a 200.
- `crawl` finds only linked pages. A route nothing links to must either get a link or fail the build, never ship silently.
