Skip to content

🍕 Add modulepreload and module script support for ESM pattern#106

Open
jjpaulino wants to merge 6 commits intomasterfrom
jordan/yolo-update
Open

🍕 Add modulepreload and module script support for ESM pattern#106
jjpaulino wants to merge 6 commits intomasterfrom
jordan/yolo-update

Conversation

@jjpaulino
Copy link
Copy Markdown
Member

@jjpaulino jjpaulino commented Apr 13, 2026

Summary

Extends amphora-html so sites using the modern JS pipeline (content-hashed ESM) can emit <script type="module"> and optional <link rel="modulepreload">, control cache-busting for those URLs, and give resolveMedia enough context for per-component manifest logic. Also includes smaller media/render improvements (linked font CSS, richer post-render hooks) and prerelease version bumps.

Changes

ESM / modulepreload (opt-in)

  • New tag types in lib/media.js: module<script type="module" src="…">, modulepreload<link rel="modulepreload" href="…">.
  • configure({ modulepreload: true }) (wired through lib/render.jsmediaService.configure) turns on modulepreload injection and sets omitCacheBusterOnModules so hashed ESM assets can skip the extra ?version= query when appropriate.
  • injectScriptsAndStyles: resolves mediaMap.moduleScripts and mediaMap.modulePreloads, prepends modulepreload hints before combined CSS in <head>, and appends module scripts before classic scripts at </body>.
  • Sets locals._components from state._components before calling setup.resolveMedia, so sites can implement manifest / per-component script selection without carrying the full state object.

Linked font stylesheets

  • getStyleFiles also picks up _linked-fonts._default.css and _linked-fonts.<siteStyleguide>.css when they exist (clay compile–linked font flow).

Post-render hooks

  • postRender plugins now receive res and the layout/page meta ref (meta._ref) in addition to ref, html, and locals, so hooks can depend on the response or the rendered ref when needed.

Versioning

  • Package version advanced along the branch (e.g. 6.0.0-dev.0, 6.0.1-dev.0) — align release notes with whatever you actually publish.

Backward compatibility

  • modulepreload defaults off; existing sites that don’t set it behave as before.
  • Classic script and style behavior is unchanged unless new mediaMap fields and configure({ modulepreload: true }) are used.

Testing / verification

  • Smoke-render pages with and without modulepreload enabled.
  • With modulepreload: true, confirm HTML includes expected modulepreload + module script tags and that resolveMedia sees locals._components when needed.
  • Confirm postRender plugins that use the new arguments behave as intended (or remain backward compatible if they ignore extra args).

james-owen and others added 6 commits November 4, 2022 12:48
- Add MODULE_SCRIPT_TAG and MODULEPRELOAD_TAG constants to media.js
- Add omitCacheBusterOnModules flag (enabled when modulepreload:true) so
  content-hashed ESM filenames skip the redundant ?version= query string
- Handle moduleScripts and modulePreloads in injectScriptsAndStyles(),
  injecting <script type="module"> at </body> and <link rel="modulepreload">
  in <head> (before CSS) for earliest possible browser fetch
- Expose locals._components before resolveMedia callback so sites can do
  per-component manifest lookup without holding a full state reference
- Update configure() in both media.js and render.js to accept modulepreload
  option; defaults to false for full backwards compatibility

Made-with: Cursor
@jjpaulino jjpaulino self-assigned this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants