Skip to content

[MWPW-TBD] Optimize personalization module loading — eliminate serial fetch waterfall#6206

Closed
mokimo wants to merge 2 commits into
stagefrom
mokimo-perf-personalization-preload
Closed

[MWPW-TBD] Optimize personalization module loading — eliminate serial fetch waterfall#6206
mokimo wants to merge 2 commits into
stagefrom
mokimo-perf-personalization-preload

Conversation

@mokimo

@mokimo mokimo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

On pages with personalization enabled (e.g. adobe.com/fr/creativecloud.html), the personalization module chain loaded fully serially:

Step Module Start Delay
1 personalization.js t=499ms
2 sanitizeHtml.js (static import, discovered at parse) t=540ms +41ms serial
3 promo-utils.js (dynamic import fired in init()) t=584ms +44ms serial

~130ms of avoidable serial latency before personalization could apply changes to the DOM.

Fix 1 — modulepreload for personalization deps (utils.js)

Added modulepreload hints for personalization.js and (when promo is enabled) promo-utils.js in checkForPageMods(), placed before the getCountry() await. Both fetches now start during country detection rather than after it, and are in the browser module cache by the time await import() fires.

Fix 2 — Inline sanitizeHtml.js into personalization.js

sanitizeHtml.js had exactly one consumer (personalization.js) and was always required via a static import — making it a guaranteed serial fetch. Moving the logic directly into personalization.js eliminates the file and the extra request entirely. sanitizeHtmlBody is exported from personalization.js for testability; the standalone file is deleted.

Result: all three modules now start fetching in parallel.

Before: personalization.js(40ms) → sanitizeHtml.js(43ms) → promo-utils.js(48ms) ≈ 130ms serial
After:  all three start together (during getCountry await) ≈ 50ms parallel

To observe: DevTools → Network → filter JS → waterfall for personalization.js / promo-utils.js on any personalized page.


Test URLs (milo branch vs main on the observed page):

Test URLs (milo standalone preview):

🤖 Generated with Claude Code

Before
Personalization -> sanitize-html -> promo-utils
image

After
Personalization+promo utils in parallel, inline always needed sanitizehtml
image

mokimo and others added 2 commits June 22, 2026 13:16
personalization.js, sanitizeHtml.js (static import), and promo-utils.js
were loaded serially — each triggered only after the previous finished.
On adobe.com/fr/creativecloud this created a ~130ms serial chain starting
at t=499ms (personalization → +41ms sanitizeHtml → +44ms promo-utils).

Adding modulepreload hints for all three in checkForPageMods(), before the
getCountry() await, overlaps their fetches with country detection so the
browser has them in the module cache by the time await import() fires.
Verified locally: all three now start in parallel at the same timestamp.

Also deduplicates the getConfig().base call in the same block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…request

sanitizeHtml.js had a single consumer (personalization.js) and was always
loaded as a static import — meaning every page with personalization paid
for an extra serial module fetch. Moving the logic directly into
personalization.js eliminates that request entirely.

- Inline stringToHTML, isPossiblyDangerous, sanitizeHtmlNode, and
  sanitizeHtmlBody into personalization.js as private functions
  (sanitizeHtmlBody exported for testability)
- Delete libs/utils/sanitizeHtml.js
- Remove the now-unnecessary modulepreload hint for sanitizeHtml.js
- Update sanitizeHtml.test.js to import from personalization.js and
  drop the sanitizeHtml (firstChild) describe block — that export is gone

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mokimo mokimo requested a review from a team as a code owner June 22, 2026 11:16
@aem-code-sync

aem-code-sync Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@mokimo

mokimo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Closed in favor of #6210

@mokimo mokimo closed this Jun 22, 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.

1 participant