Skip to content

Commit

Permalink
faces.js getScripts(html) optimized
Browse files Browse the repository at this point in the history
Signed-off-by: pizzi80 <[email protected]>
  • Loading branch information
pizzi80 committed May 9, 2024
1 parent 9a53ad7 commit b823023
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,18 @@ if ( !( (window.faces && window.faces.specversion && window.faces.specversion >=
*/
const getScripts = function getScripts(html) {
const scripts = [];
const initialnodes = html.match(SCRIPT_TAG_REGEX);
while (!!initialnodes && initialnodes.length > 0) {
let scriptStr = [];
scriptStr = initialnodes.shift().match(SINGLE_SCRIPT_TAG_REGEX); // todo: multiple shift array ... rewrite this algo
// check the type - skip if specified but not text/javascript
const type = scriptStr[1].match(TAG_ATTRIBUTE_TYPE_REGEX);
if (!!type && type[1] !== "text/javascript") {
continue;
const matchingNodes = html.match(SCRIPT_TAG_REGEX);

if (matchingNodes && matchingNodes.length > 0) {
for (const node of matchingNodes) {
const scriptStr = node.match(SINGLE_SCRIPT_TAG_REGEX);
// check the type - skip if specified but not text/javascript (json+ld for example)
const type = scriptStr[1].match(TAG_ATTRIBUTE_TYPE_REGEX);
if (!!type && type[1] !== "text/javascript") {
continue;
}
scripts.push(scriptStr);
}
scripts.push(scriptStr);
}
return scripts;
};
Expand Down

0 comments on commit b823023

Please sign in to comment.