Skip to content

Commit

Permalink
fix(load): Optimize check resources loaded function
Browse files Browse the repository at this point in the history
  • Loading branch information
gyx8899 committed Sep 1, 2020
1 parent 16cc70e commit 05c6a74
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/util/Load.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,10 @@ function loadResources(urls, callback) {
* @returns {boolean}
*/
function checkResourceLoaded(url) {
let type = getUrlTypeInfo(url),
typeSelector = type['tagName'] || '[src]',
allUrls = Array.prototype.slice.call(document.querySelectorAll(typeSelector))
.map(function (scriptElement) {
return scriptElement[type['urlAttrName']];
});
return allUrls.indexOf(url) !== -1;
let type = getFileNameFromURL(url).extensionName;
let selector = (type === 'js' && `script[src="${url}"]`)
|| (type === 'css' && `link[href="${url}"]`) || null;
return !!selector && !!document.querySelector(selector);
}

/***
Expand Down

0 comments on commit 05c6a74

Please sign in to comment.