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

Function appendPreloadHintsToHtml

packages/angular/ssr/src/app.ts:536–550  ·  view source on GitHub ↗

* Appends module preload hints to an HTML string for specified JavaScript resources. * This function enhances the HTML by injecting ` ` elements * for each provided resource, allowing browsers to preload the specified JavaScript * modules for better performance. * * @pa

(html: string, preload: readonly string[])

Source from the content-addressed store, hash-verified

534 * If `</body>` is not found, the links are not added.
535 */
536function appendPreloadHintsToHtml(html: string, preload: readonly string[]): string {
537 const bodyCloseIdx = html.lastIndexOf('</body>');
538 if (bodyCloseIdx === -1) {
539 return html;
540 }
541
542 // Note: Module preloads should be placed at the end before the closing body tag to avoid a performance penalty.
543 // Placing them earlier can cause the browser to prioritize downloading these modules
544 // over other critical page resources like images, CSS, and fonts.
545 return [
546 html.slice(0, bodyCloseIdx),
547 ...preload.map((val) => `<link rel="modulepreload" href="${val}">`),
548 html.slice(bodyCloseIdx),
549 ].join('\n');
550}

Callers 1

runTransformsOnHtmlMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected