Repository navigation
Description
Summary
New rule perf/content-in-js-bundle: flag pages whose JS chunks contain the site's page content (compiled MDX or markdown bodies, inlined JSON), so it ships to every visitor as script instead of being rendered on the server.
Why
Found on a real site: a TanStack Start site used eager import.meta.glob("content/*.mdx"). Every MDX body was compiled to JS and bundled into the entry chunk (1.7 MB, about 490 KB gzipped) for about 150 files. Every page load downloaded the text of every other page. The HTML was already server-rendered, so the content shipped twice. After rendering bodies on the server, the entry chunk dropped to 617 KB (189 KB gzipped).
Existing rules did not point at the cause:
perf/js-file-sizesays a file is big but not whyperf/total-byte-weightis sitewideperf/duplicate-jsis about duplicate libraries
The pattern is common with MDX/Markdown on Vite, Next, Astro islands and Remix, and with CMS JSON imported at build time.
Detection (black box)
- For each audited page, take 3 to 5 distinctive sentences from the visible main content (10 or more words each, not in nav or footer).
- Search the page's same-origin JS chunks (after decompression) for those strings. Allow for JSX/escaped quotes and entity forms.
- Flag
perf/content-in-js-bundlewhen the page's own body text is in script. - Escalate severity when the same chunk also contains body text from other crawled pages. That is the "whole site's content in every page's bundle" signature.
- Report: chunk URL, size (raw and gzipped), number of other pages' content found in it, and an estimated share of the chunk that is prose.
Low false-positive risk: framework hydration state lives in the HTML, not in a script chunk, and a script file holding prose from many other pages is rarely intentional. Skip chunks under about 50 KB, and skip the page's own inline JSON-LD.
Suggested advice text
Render static content on the server and keep it out of the client bundle. For MDX: compile and render bodies in a server function or loader, import only frontmatter on the client, and use lazy (not eager) globs for bodies. For frameworks with server components, keep content in server components.
Notes
- Related:
perf/js-file-size,perf/total-byte-weight,perf/duplicate-js. - Needs a test fixture: a page with its body text and a chunk containing it, plus a negative with only hydration JSON in the HTML.
Acceptance Criteria
- A fixture site with a server-rendered page whose same-origin JS chunk (≥50 KB) contains 3+ of that page's distinctive main-content sentences produces
perf/content-in-js-bundleon that page. The finding gives the chunk URL, raw and gzipped size, and the estimated prose share. - When the same chunk also holds main-content sentences from other crawled pages, the finding escalates (higher severity or a site-wide variant) and reports how many other pages' content it found.
- Sentences are matched through JSX-escaped quotes,
\n/\uescapes and HTML entities (a test for each form). - No finding when the content is only in the HTML (inline hydration JSON,
__NEXT_DATA__-style state, JSON-LD), when chunks are under ~50 KB, or when the matched text comes from nav or footer. - Chunk fetching reuses the existing JS asset fetches, so each chunk is downloaded and decompressed once per audit, with the same size and time limits as other asset rules. A test shows a huge chunk is bounded.
- Rule added in all four places (rule file, category index,
docs/rules/perf/page, rule counts), with any verdictScope or measurement fixture entry it needs;make validatepasses. -
scripts/test-suites.ts --run rulespasses.
Activity
feat(rules): perf/content-in-js-bundle finds page content compiled in…
fix(rules): read the body of an empty document without throwing (#1200)
fix(rules): linear, bounded decoding and matching in content-in-script (
feat(rules): perf/content-in-js-bundle finds page content compiled in…
fix(rules): read the body of an empty document without throwing (#1200)
fix(rules): linear, bounded decoding and matching in content-in-script (
feat(rules): perf/content-in-js-bundle finds page content compiled in…
fix(rules): read the body of an empty document without throwing (#1200)
fix(rules): linear, bounded decoding and matching in content-in-script (
fix(rules): nested landmarks, rendered pages, honest partial and unch…
feat(rules): perf/content-in-js-bundle finds page content compiled in…
fix(rules): read the body of an empty document without throwing (#1200)
fix(rules): linear, bounded decoding and matching in content-in-script (
fix(rules): nested landmarks, rendered pages, honest partial and unch…
nc9 commentedon Oct 30, 2026
Shipped in v0.0.143 (commits 662565a, 02e3ac8, fb39c59, 24a2b03). Checked every acceptance criterion against current main: perf/content-in-js-bundle in all four places, docs, tests, golden updated;
make validateand main CI pass.nik