Skip to content

Commit

Permalink
golf: compress support helper;
Browse files Browse the repository at this point in the history
- run the `document` check first
- 720 gz / 596 br
  • Loading branch information
lukeed committed Dec 14, 2018
1 parent 6924af0 commit 9df00ff
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/prefetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ const preFetched = {};
* @return {Boolean} whether the feature is supported
*/
function support(feature) {
if (typeof document === `undefined`) {
return false;
}
try {
const fakeLink = document.createElement(`link`);
if (fakeLink.relList && typeof fakeLink.relList.supports === `function`) {
return fakeLink.relList.supports(feature);
}
} catch (err) {
return false;
}
};
const link = document.createElement('link');
return (link.relList || {}).supports && link.relList.supports(feature);
}

/**
* Fetches a given URL using `<link rel=prefetch>`
Expand Down Expand Up @@ -94,7 +85,7 @@ function highPriFetchStrategy(url) {
: fetch(url, {credentials: `include`});
}

const supportedPrefetchStrategy = support(`prefetch`)
const supportedPrefetchStrategy = typeof document !== 'undefined' && support('prefetch')
? linkPrefetchStrategy
: xhrPrefetchStrategy;

Expand Down

0 comments on commit 9df00ff

Please sign in to comment.