MWPW-201399 Preload MAS fragments - #6393
Conversation
|
This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR. |
| const DEFAULT_MAS_FRAGMENT_API_KEY = 'wcms-commerce-ims-ro-user-milo'; | ||
|
|
||
| // Kept in sync with GeoMap in blocks/merch/merch.js. | ||
| const MAS_GEO_MAP = { |
There was a problem hiding this comment.
@TsayAdobe I find it risky to duplicate mas GEO in a different file.
the fragment must be fetched with the right parameters once Milo initializes fully with the Lingo logic.
maybe you can move this logic around isLcpSection and import merch.js to let commerce initialize and then use it to read country/locale/api key etc.
There was a problem hiding this comment.
@yesil For performance purposes, we should move more merch initialization services into Milo’s utils.js. We can then preload merch scripts and prefetch fragments. We can externalize mas GEO in utils.js and have the merch scripts import it.
How often do we update a fragment’s ID or country in a way that makes prefetching ineffective? If that happens less than 10% of the time, I think prefetching is still a net win.
There was a problem hiding this comment.
I agree but we should use merch.js to initialize it.
Maybe even before decorateAutoBlock, you can check if there is merch in the LCP block, load merch.js first, init commerce and and use it to preload the fragment.
narcis-radu
left a comment
There was a problem hiding this comment.
A lot of MAS related logic that's going to be loaded by all Milo consumers, regardless of whether they use MAS or not. The code should not live inside utils.js, and should be loaded only when / if needed.
|
@TsayAdobe just an idea because I know we need this fix , is there a super lightweight file we could load from m@s as quickly as possible if a m@s autoblock is in LCP, which holds the mas geo information and kicks off the fragment load and everything else, so that there's still just one file in M@S with that information, but we're also kicking the load off as fast as we can ? |
@narcis-radu This needs to run synchronously inside decorateAutoBlock, before any async work, so the preload fires in the same tick a MAS link is recognized — that's what lets it win the race against the block's own fetch. Deferring it to a dynamic import would push it past that tick and defeat the purpose. On pages that don't use MAS, the cost is just the early-return check against MAS_FRAGMENT_AUTOBLOCKS — no request, no locale/geo work runs. |
@vhargrave Lightweight doesn't solve this — for a file this small, the cost is almost entirely the network round-trip (DNS + connection + request/response), not transfer time, so shrinking the payload barely helps. Any separately-hosted file still costs a full extra RTT we don't pay today. utils.js is already part of Milo's bootstrap and loads on every page regardless, so folding the geo data into it adds zero extra requests — we're just parsing a few more KB of a file already in flight. That's why this needs to live in utils.js, not a separate file, even a tiny one. |
@TsayAdobe fair - alright, two comments from my end then
If you do that then this looks good to me . |
|
Thanks, @TsayAdobe. Would it be possible to check whether M@S is in use before |
|
This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label. |

As more pages integrate with MAS, prefetching MAS fragment content is important for performance. This PR adds an early prefetch for MAS fragment URLs referenced on the marquee: as soon as a MAS-fragment autoblock link (merch-card, merch-card-collection, mas-compare-chart) is recognized during autoblock decoration, its fragment URL is preloaded — before the block itself would otherwise request it.
Since the locale/country derivation needed to build a matching URL depends on merch.js's GeoMap, a copy of that lookup table was added to utils.js (MAS_GEO_MAP).
Resolves: MWPW-201399
Test URLs:
The following tests was done with content overrides on www.adobe.com. In the file
/mas/libs/merch-cards.js,credentials:"omit"should be replaced withcredentials:"same-origin". Then replace the file/libs/utils/utils.jswith the one in this PR. Environment settings: CPU: 4X slowdown, Network: Fast 4G, and Disable network cache.(when mep is on, the marquee is replaced and it doesn't use a MAS fragment)
The call
/mas/io/fragmentis usually taking about 200ms to 800ms blocking the LCP.The fragment is preloaded and the LCP is done earlier.