* 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)
| 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">`. |
no test coverage detected