UNPKG

assetgraph

Version:

An auto discovery dependency graph based optimization framework for web pages and applications

30 lines (23 loc) 789 B
const HtmlResourceHint = require('./HtmlResourceHint'); /** * @extends {HtmlResourceHint} * * Implementation of https://www.w3.org/TR/resource-hints/#prefetch */ class HtmlPrefetchLink extends HtmlResourceHint { attach(position, adjacentRelation) { this.node = this.from.parseTree.createElement('link'); this.node.setAttribute('rel', 'prefetch'); if (this.contentType && this.contentType !== 'application/octet-stream') { this.node.setAttribute('type', this.contentType); } if (this.as) { this.node.setAttribute('as', this.as); if (['font', 'fetch'].includes(this.as)) { this.node.setAttribute('crossorigin', 'anonymous'); } } return super.attach(position, adjacentRelation); } } module.exports = HtmlPrefetchLink;