Home / Function/ preloadStyleLinks() — astro Function Reference

preloadStyleLinks() — astro Function Reference

Architecture documentation for the preloadStyleLinks() function in router.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  a3f6f1d3_8ee5_3af7_2e71_96af3c87e27c["preloadStyleLinks()"]
  2b5c33e2_176e_e839_f05f_7f10493f4f74["router.ts"]
  a3f6f1d3_8ee5_3af7_2e71_96af3c87e27c -->|defined in| 2b5c33e2_176e_e839_f05f_7f10493f4f74
  6b23b6bb_d4a4_83cb_3896_2e31c0316793["transition()"]
  6b23b6bb_d4a4_83cb_3896_2e31c0316793 -->|calls| a3f6f1d3_8ee5_3af7_2e71_96af3c87e27c
  style a3f6f1d3_8ee5_3af7_2e71_96af3c87e27c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/transitions/router.ts lines 244–268

function preloadStyleLinks(newDocument: Document) {
	const links: Promise<any>[] = [];
	for (const el of newDocument.querySelectorAll('head link[rel=stylesheet]')) {
		// Do not preload links that are already on the page.
		if (
			!document.querySelector(
				`[${PERSIST_ATTR}="${el.getAttribute(
					PERSIST_ATTR,
				)}"], link[rel=stylesheet][href="${el.getAttribute('href')}"]`,
			)
		) {
			const c = document.createElement('link');
			c.setAttribute('rel', 'preload');
			c.setAttribute('as', 'style');
			c.setAttribute('href', el.getAttribute('href')!);
			links.push(
				new Promise<any>((resolve) => {
					['load', 'error'].forEach((evName) => c.addEventListener(evName, resolve));
					document.head.append(c);
				}),
			);
		}
	}
	return links;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does preloadStyleLinks() do?
preloadStyleLinks() is a function in the astro codebase, defined in packages/astro/src/transitions/router.ts.
Where is preloadStyleLinks() defined?
preloadStyleLinks() is defined in packages/astro/src/transitions/router.ts at line 244.
What calls preloadStyleLinks()?
preloadStyleLinks() is called by 1 function(s): transition.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free