assetgraph
Version:
An auto discovery dependency graph based optimization framework for web pages and applications
17 lines (16 loc) • 530 B
JavaScript
module.exports = (queryObj, setAsyncAttribute, setDeferAttribute) => {
return function setAsyncOrDeferOnHtmlScripts(assetGraph) {
if (setAsyncAttribute || setDeferAttribute) {
for (const htmlScript of assetGraph.findRelations(
Object.assign({ type: 'HtmlScript' }, queryObj)
)) {
if (setAsyncAttribute) {
htmlScript.node.setAttribute('async', 'async');
}
if (setDeferAttribute) {
htmlScript.node.setAttribute('defer', 'defer');
}
}
}
};
};