assetgraph
Version:
An auto discovery dependency graph based optimization framework for web pages and applications
30 lines (23 loc) • 717 B
JavaScript
const HtmlResourceHint = require('./HtmlResourceHint');
/**
* @extends {HtmlResourceHint}
*
* Implementation of http://w3c.github.io/preload/#dfn-preload
*/
class HtmlPreloadLink extends HtmlResourceHint {
attach(position, adjacentRelation) {
this.node = this.from.parseTree.createElement('link');
this.node.setAttribute('rel', 'preload');
if (this.as) {
this.node.setAttribute('as', this.as);
}
if (this.contentType) {
this.node.setAttribute('type', this.contentType);
}
if (['font', 'fetch'].includes(this.as)) {
this.node.setAttribute('crossorigin', 'anonymous');
}
super.attach(position, adjacentRelation);
}
}
module.exports = HtmlPreloadLink;