Skip to content

feat(layout): lean asset registration script - #74

Merged
dgaponov merged 1 commit into
mainfrom
feat/lean-asset-registration
Oct 21, 2026
Merged

dgaponov merged 1 commit into
mainfrom
feat/lean-asset-registration

Conversation

@dgaponov

@dgaponov dgaponov commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Follow-up to #72. The registration script repeated every asset URL three times: in the asset list (originalUrl), in the pre-rendered document.write recovery string, and (unavoidably) in the preload link. Now it is written once.

  1. originalUrl is gone from the serialized asset. It was always publicPath + path by construction (createScriptAsset/createStyleAsset only manage URLs under publicPath), so the runtime derives it: for the dedup key, for the first attempt, and for app-layout:asset-load-error (detail.originalUrl is unchanged for consumers).
  2. Recovery tags are rebuilt in the browser from the same list (<link rel="stylesheet"> / <script defer> with crossorigin and nonce), instead of embedding the pre-rendered tags as a second copy. & and " in URLs are escaped, </script> is split.

Before / after on real head (6 CSS + 16 JS):

raw gzip brotli
registration block, 2.7.0 8.3 KB 985 B 844 B
registration block, this PR 2.6 KB 881 B 743 B

Mostly a readability win in the emitted HTML; the wire gain is ~100 B per page.

What does not change

  • Runtime behaviour: same queue, timeouts, retries, events. runtime.ts only replaces three asset.originalUrl reads with publicPath + path.
  • Without publicPathFallbacks the output is byte-for-byte the same.
  • Asset is internal (not exported); serializeAssetRegistrations(assets, publicPath) replaces (assets, originalHtml).

Tests

  • serialization.test.ts: recovery now asserted on the rebuilt tags (stylesheet, script with crossorigin+nonce, script without crossorigin, & escaping); existing bootstrap-failure cases updated to the rebuilt form.
  • render.test.ts / runtime.test.ts: adjusted for the new asset shape.
  • tsc, eslint, 43/43.

🤖 Generated with Claude Code

- drop originalUrl from the serialized asset: the primary URL is always
  publicPath + path, the runtime derives it (dedup key, first attempt, event detail)
- build the document.write recovery tags in the browser from the same asset list
  instead of embedding the pre-rendered tags as a string

Every asset URL was written three times into the registration script (list,
recovery string, preload link); now once. On Cloud Console's head (6 CSS + 16 JS)
the registration block goes from 8.3 KB to 2.6 KB raw (985 B to 881 B gzipped).
Loader behaviour is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@DanilaBeseda
DanilaBeseda self-requested a review October 21, 2026 10:38
@dgaponov
dgaponov merged commit 8b804e7 into main Oct 21, 2026
2 checks passed
@dgaponov
dgaponov deleted the feat/lean-asset-registration branch October 21, 2026 11:59
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