Skip to content

New rule: perf/content-in-js-bundle (page content shipped in client JS) #1200

Closed

Description

@nc9

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-size says a file is big but not why
  • perf/total-byte-weight is sitewide
  • perf/duplicate-js is 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)

  1. 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).
  2. Search the page's same-origin JS chunks (after decompression) for those strings. Allow for JSX/escaped quotes and entity forms.
  3. Flag perf/content-in-js-bundle when the page's own body text is in script.
  4. 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.
  5. 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-bundle on 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/\u escapes 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 validate passes.
  • scripts/test-suites.ts --run rules passes.

Activity

  1. added
    enhancement
    performance
    on Oct 27, 2026
  2. added theissue type on Oct 28, 2026
  3. added
    rules
    size: L
    on Oct 28, 2026
  4. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    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 validate and main CI pass.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementperformancerulessize: L

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions