Extract snippets to external JS files#60
Merged
Conversation
All 48 JavaScript snippets are extracted from inline MDX code blocks into
standalone .js files under snippets/{category}/, making them individually
addressable by LLMs and agents.
- Add snippets/ directory with 48 .js files organized by category
(CoreWebVitals, Interaction, Loading, Media, Resources)
- Add components/Snippet.jsx: renders raw JS with highlight.js syntax
highlighting, copy button, max-height scroll, and dark/light mode support
- Add scripts/extract-snippets.js: one-time migration script that extracted
code blocks from ### Snippet sections and rewrote MDX imports
- Update all 46 MDX pages to import snippets via ?raw and use <Snippet>
- Update next.config.js: webpack asset/source rule for ?raw imports,
injected into oneOf to take precedence over SWC, with pre-loaders
excluded to prevent React Fast Refresh injection
- Update styles/globals.css: hljs light/dark themes, override Nextra's
`pre code { padding: 0 !important }`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
nucliweb
added a commit
that referenced
this pull request
Mar 2, 2026
Extract snippets to external JS files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All 48 JavaScript snippets are extracted from inline MDX code blocks into standalone
.jsfiles, making each snippet individually addressable by path — enabling LLMs and agents to reference, read, and analyze them directly.Changes
New:
snippets/directory48
.jsfiles organized by category, mirroring the pages structure:snippets/CoreWebVitals/— 7 files (CLS, INP, LCP, LCP-Sub-Parts, LCP-Trail, LCP-Image-Entropy, LCP-Video-Candidate)snippets/Interaction/— 8 filessnippets/Loading/— 27 files (including TTFB, TTFB-Sub-Parts, TTFB-Resources)snippets/Media/— 3 filessnippets/Resources/— 1 fileEach file contains the raw, executable JavaScript as-is — valid for pasting directly into the browser DevTools console.
New:
components/Snippet.jsxReact component that renders external snippet files with:
highlight.js(light/dark mode)max-height: 300pxwith vertical scroll to avoid long pagesNew:
scripts/extract-snippets.jsOne-time migration script that extracted all inline code blocks from
### Snippetsections in MDX files and rewrote them asimport+<Snippet>usage. Kept in the repo for reference and future use.Updated: all 46 MDX pages in
pages/Each page now imports its snippet(s) as raw strings and renders them via
<Snippet>:For pages with multiple snippets (e.g. TTFB), each section imports its own file with a semantic name derived from the H2 heading.
Updated:
next.config.jsCustom webpack rule to import
.jsfiles fromsnippets/as raw strings via?raw:oneOfblock to take precedence over the SWC loadersnippets/to prevent HMR code injectionimport foo from './snippets/X.js?raw'yields the unmodified source stringUpdated:
styles/globals.csshighlight.jsCSS for light mode (GitHub style) and dark mode (Atom One Dark)pre code { padding: 0 !important }using.nextra-code-block pre codeTest plan
max-heightscroll works on long snippets