MCPcopy Index your code
hub / github.com/ampproject/amphtml / preload

Method preload

src/preconnect.js:199–222  ·  view source on GitHub ↗

* Asks the browser to preload a URL. Always also does a preconnect * because browser support for that is better. * * It is safe to call this method during prerender with any value, * because no action will be performed until the doc is visible. * * It is safe to call this method wi

(ampdoc, url, opt_preloadAs)

Source from the content-addressed store, hash-verified

197 * @param {string=} opt_preloadAs
198 */
199 preload(ampdoc, url, opt_preloadAs) {
200 if (!this.isInterestingUrl_(url)) {
201 return;
202 }
203 if (this.urls_[url]) {
204 return;
205 }
206 this.urls_[url] = true;
207 this.url(ampdoc, url, /* opt_alsoConnecting */ true);
208 if (!this.features_.preload) {
209 return;
210 }
211 if (opt_preloadAs == 'document' && this.platform_.isSafari()) {
212 // Preloading documents currently does not work in Safari,
213 // because it
214 // - does not support preloading iframes
215 // - and uses a different cache for iframes (when loaded without
216 // as attribute).
217 return;
218 }
219 ampdoc.whenFirstVisible().then(() => {
220 this.performPreload_(url);
221 });
222 }
223
224 /**
225 * Performs a preload using `<link rel="preload">`.

Callers 1

preloadBootstrapFunction · 0.45

Calls 6

isInterestingUrl_Method · 0.95
urlMethod · 0.95
performPreload_Method · 0.95
isSafariMethod · 0.80
thenMethod · 0.45
whenFirstVisibleMethod · 0.45

Tested by

no test coverage detected