Skip to content

Commit

Permalink
update depCache preload to support safari
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 12, 2017
1 parent 31e3e5b commit 2b64def
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/common.js
Expand Up @@ -82,24 +82,34 @@ export function extendMeta (a, b, _prepend) {
}
}

var supportsPreload = isBrowser && (function () {
var relList = document.createElement('link').relList;
if (relList && relList.supports) {
try {
return relList.supports('preload');
var supportsPreload = false, supportsPrefetch = false;
if (isBrowser)
(function () {
var relList = document.createElement('link').relList;
if (relList && relList.supports) {
supportsPrefetch = true;
try {
supportsPreload = relList.supports('preload');
}
catch (e) {}
}
catch (e) {}
}
return false;
})();
})();

export function preloadScript (url) {
// fallback to old fashioned image technique which still works in safari
if (!supportsPreload && !supportsPrefetch) {
var preloadImage = new Image();
preloadImage.src = url;
return;
}

var link = document.createElement('link');
if (supportsPreload) {
link.rel = 'preload';
link.as = 'script';
}
else {
// this works for all except Safari (detected by relList.supports lacking)
link.rel = 'prefetch';
}
link.href = url;
Expand Down

0 comments on commit 2b64def

Please sign in to comment.