Home / Function/ initViewportStrategy() — astro Function Reference

initViewportStrategy() — astro Function Reference

Architecture documentation for the initViewportStrategy() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9["initViewportStrategy()"]
  315e53ea_6d34_137c_ce5c_8c89aca90db9["index.ts"]
  8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9 -->|defined in| 315e53ea_6d34_137c_ce5c_8c89aca90db9
  6ed5ea2f_503c_fb78_a8ee_5c3ea9f2de4f["init()"]
  6ed5ea2f_503c_fb78_a8ee_5c3ea9f2de4f -->|calls| 8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9
  c855800f_f956_d749_63eb_d18456243299["onPageLoad()"]
  8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9 -->|calls| c855800f_f956_d749_63eb_d18456243299
  70bfc884_b3b0_e84b_4b73_06d369aade2b["elMatchesStrategy()"]
  8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9 -->|calls| 70bfc884_b3b0_e84b_4b73_06d369aade2b
  41ad7978_6a9c_8215_6479_75ce204d7cbd["createViewportIntersectionObserver()"]
  8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9 -->|calls| 41ad7978_6a9c_8215_6479_75ce204d7cbd
  style 8c99d8e4_b1d5_84e4_ba47_c797c9e87ba9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/prefetch/index.ts lines 127–142

function initViewportStrategy() {
	let observer: IntersectionObserver;

	onPageLoad(() => {
		for (const anchor of document.getElementsByTagName('a')) {
			// Skip if already listening
			if (listenedAnchors.has(anchor)) continue;
			// Observe for anchors matching the strategy
			if (elMatchesStrategy(anchor, 'viewport')) {
				listenedAnchors.add(anchor);
				observer ??= createViewportIntersectionObserver();
				observer.observe(anchor);
			}
		}
	});
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does initViewportStrategy() do?
initViewportStrategy() is a function in the astro codebase, defined in packages/astro/src/prefetch/index.ts.
Where is initViewportStrategy() defined?
initViewportStrategy() is defined in packages/astro/src/prefetch/index.ts at line 127.
What does initViewportStrategy() call?
initViewportStrategy() calls 3 function(s): createViewportIntersectionObserver, elMatchesStrategy, onPageLoad.
What calls initViewportStrategy()?
initViewportStrategy() is called by 1 function(s): init.

Analyze Your Own Codebase

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

Try Supermodel Free