🍕 Add modulepreload and module script support for ESM pattern#106
Open
🍕 Add modulepreload and module script support for ESM pattern#106
Conversation
- 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
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
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 giveresolveMediaenough 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)
lib/media.js:module→<script type="module" src="…">,modulepreload→<link rel="modulepreload" href="…">.configure({ modulepreload: true })(wired throughlib/render.js→mediaService.configure) turns on modulepreload injection and setsomitCacheBusterOnModulesso hashed ESM assets can skip the extra?version=query when appropriate.injectScriptsAndStyles: resolvesmediaMap.moduleScriptsandmediaMap.modulePreloads, prepends modulepreload hints before combined CSS in<head>, and appends module scripts before classic scripts at</body>.locals._componentsfromstate._componentsbefore callingsetup.resolveMedia, so sites can implement manifest / per-component script selection without carrying the full state object.Linked font stylesheets
getStyleFilesalso picks up_linked-fonts._default.cssand_linked-fonts.<siteStyleguide>.csswhen they exist (clay compile–linked font flow).Post-render hooks
postRenderplugins now receiveresand the layout/page meta ref (meta._ref) in addition toref,html, andlocals, so hooks can depend on the response or the rendered ref when needed.Versioning
6.0.0-dev.0,6.0.1-dev.0) — align release notes with whatever you actually publish.Backward compatibility
modulepreloaddefaults off; existing sites that don’t set it behave as before.mediaMapfields andconfigure({ modulepreload: true })are used.Testing / verification
modulepreloadenabled.modulepreload: true, confirm HTML includes expected modulepreload + module script tags and thatresolveMediaseeslocals._componentswhen needed.postRenderplugins that use the new arguments behave as intended (or remain backward compatible if they ignore extra args).