MCPcopy Create free account
hub / github.com/ampproject/amphtml / getPreconnectFeatures

Function getPreconnectFeatures

src/preconnect.js:36–51  ·  view source on GitHub ↗

* Detect related features if feature detection is supported by the * browser. Even if this fails, the browser may support the feature. * @param {!Window} win * @return {!PreconnectFeaturesDef}

(win)

Source from the content-addressed store, hash-verified

34 * @return {!PreconnectFeaturesDef}
35 */
36function getPreconnectFeatures(win) {
37 if (!preconnectFeatures) {
38 const linkTag = win.document.createElement('link');
39 const tokenList = linkTag['relList'];
40 linkTag.as = 'invalid-value';
41 if (!tokenList || !tokenList.supports) {
42 return {};
43 }
44 preconnectFeatures = {
45 preconnect: tokenList.supports('preconnect'),
46 preload: tokenList.supports('preload'),
47 onlyValidAs: linkTag.as != 'invalid-value',
48 };
49 }
50 return preconnectFeatures;
51}
52
53/**
54 * @param {?PreconnectFeaturesDef} features

Callers 1

constructorMethod · 0.85

Calls 1

supportsMethod · 0.80

Tested by

no test coverage detected