* 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)
| 34 | * @return {!PreconnectFeaturesDef} |
| 35 | */ |
| 36 | function 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 |