MCPcopy Index your code
hub / github.com/angular/angular-cli / appendPreloadToMetadata

Function appendPreloadToMetadata

packages/angular/ssr/src/routes/ng-routes.ts:362–387  ·  view source on GitHub ↗

* Appends preload information to the metadata object based on the specified entry-point and chunk mappings. * * This function extracts preload data for a given entry-point from the provided chunk mappings. It adds the * corresponding browser bundles to the metadata's preload list, ensuring no dup

(
  entryName: string,
  entryPointToBrowserMapping: EntryPointToBrowserMapping,
  metadata: ServerConfigRouteTreeNodeMetadata,
)

Source from the content-addressed store, hash-verified

360 * preloads to a predefined maximum.
361 */
362function appendPreloadToMetadata(
363 entryName: string,
364 entryPointToBrowserMapping: EntryPointToBrowserMapping,
365 metadata: ServerConfigRouteTreeNodeMetadata,
366): void {
367 const existingPreloads = metadata.preload ?? [];
368 if (!entryPointToBrowserMapping || existingPreloads.length >= MODULE_PRELOAD_MAX) {
369 return;
370 }
371
372 const preload = entryPointToBrowserMapping[entryName];
373 if (!preload?.length) {
374 return;
375 }
376
377 // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed.
378 const combinedPreloads: Set<string> = new Set(existingPreloads);
379 for (const href of preload) {
380 combinedPreloads.add(href);
381 if (combinedPreloads.size === MODULE_PRELOAD_MAX) {
382 break;
383 }
384 }
385
386 metadata.preload = Array.from(combinedPreloads);
387}
388
389/**
390 * Handles SSG (Static Site Generation) routes by invoking `getPrerenderParams` and yielding

Callers 1

handleRouteFunction · 0.85

Calls 2

fromMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected