Skip to content

Commit

Permalink
Merge a9e02fd into eedf76c
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Aug 24, 2014
2 parents eedf76c + a9e02fd commit c5ad4f6
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions lib/transforms/buildProduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ module.exports = function (options) {
to: {type: 'I18n'}
},
{
type: query.not(['JavaScriptInclude', 'JavaScriptExtJsRequire', 'JavaScriptCommonJsRequire', 'HtmlAnchor', 'SvgAnchor', 'JavaScriptSourceMappingUrl', 'JavaScriptSourceUrl']),
type: 'HtmlAnchor',
to: /^file:/
},
{
type: query.not(['JavaScriptInclude', 'JavaScriptExtJsRequire', 'JavaScriptCommonJsRequire', 'SvgAnchor', 'JavaScriptSourceMappingUrl', 'JavaScriptSourceUrl']),
to: {url: query.not(/^https?:/)}
});

Expand Down Expand Up @@ -172,6 +176,7 @@ module.exports = function (options) {
sizeThreshold: inlineByRelationType.CssImage,
minimumIeVersion: browsers.minimum('ie')
})
.mergeIdenticalAssets({isLoaded: true, isInline: false, type: 'Css'})
.endif()
.minifyAssets({isLoaded: true})
.if(options.addInitialHtmlExtension)
Expand Down Expand Up @@ -260,40 +265,53 @@ module.exports = function (options) {
})
.updateRelations({from: {type: 'Html', isFragment: true, nonInlineAncestor: {type: 'Rss'}}}, {hrefType: 'absolute'})
.endif()
.moveAssetsInOrder({isLoaded: true, isInline: false, type: query.not(['CacheManifest', 'Rss'])}, function (asset, assetGraph) {
// Don't rename Html assets that are linked to:
if (asset.type === 'Html' && asset.incomingRelations.some(function (incomingRelation) {
return incomingRelation.type === 'HtmlAnchor';
})) {
return;
}
var fileName = asset.fileName;
if (fileName === '.htaccess' || fileName === 'robots.txt' || fileName === 'humans.txt' || asset.url === assetGraph.root + 'favicon.ico') {
return;
}

if (!asset.isInitial || (asset.type === 'Html' && asset.isFragment)) {
var targetUrl = (options.canonicalUrl || '/') + 'static/';
// Conservatively assume that all GETSTATICURL relations pointing at non-images are intended to be fetched via XHR
// and thus cannot be put on a CDN because of same origin restrictions:
if (options.cdnRoot && asset.type !== 'Htc' && asset.extension !== '.jar' && (asset.type !== 'Html' || options.cdnHtml) && (asset.isImage || assetGraph.findRelations({to: asset, type: 'StaticUrlMapEntry'}).length === 0) || (options.cdnRoot && options.cdnFlash && asset.type === 'Flash')) {
targetUrl = options.cdnRoot;
if (/^\/\//.test(options.cdnRoot)) {
assetGraph.findRelations({to: asset}).forEach(function (incomingRelation) {
incomingRelation.hrefType = 'protocolRelative';
.moveAssetsInOrder(query.and(
{
isLoaded: true,
isInline: false,
type: query.not(['CacheManifest', 'Rss']),
fileName: query.not(['.htaccess', 'humans.txt', 'robots.txt'])
},
{
url: query.not(assetGraph.root + 'favicon.ico')
},
query.not({
type: 'Html',
incomingRelations: function (relations) {
return relations.some(function (rel) {
return rel.type === 'HtmlAnchor';
});
}
}),
query.or(
query.not({
isInitial: true
}),
{
type: 'Html',
isFragment: true
}
)), function (asset, assetGraph) {
var targetUrl = (options.canonicalUrl || '/') + 'static/';
// Conservatively assume that all GETSTATICURL relations pointing at non-images are intended to be fetched via XHR
// and thus cannot be put on a CDN because of same origin restrictions:
if (options.cdnRoot && asset.type !== 'Htc' && asset.extension !== '.jar' && (asset.type !== 'Html' || options.cdnHtml) && (asset.isImage || assetGraph.findRelations({to: asset, type: 'StaticUrlMapEntry'}).length === 0) || (options.cdnRoot && options.cdnFlash && asset.type === 'Flash')) {
targetUrl = options.cdnRoot;
if (/^\/\//.test(options.cdnRoot)) {
assetGraph.findRelations({to: asset}).forEach(function (incomingRelation) {
incomingRelation.hrefType = 'protocolRelative';

// Set crossorigin=anonymous on <script> tags pointing at CDN JavaScript.
// See http://blog.errorception.com/2012/12/catching-cross-domain-js-errors.html'
if (asset.type === 'JavaScript' && incomingRelation.type === 'HtmlScript') {
incomingRelation.node.setAttribute('crossorigin', 'anonymous');
incomingRelation.from.markDirty();
}
});
// Set crossorigin=anonymous on <script> tags pointing at CDN JavaScript.
// See http://blog.errorception.com/2012/12/catching-cross-domain-js-errors.html'
if (asset.type === 'JavaScript' && incomingRelation.type === 'HtmlScript') {
incomingRelation.node.setAttribute('crossorigin', 'anonymous');
incomingRelation.from.markDirty();
}
});
}
}
}
return targetUrl + asset.fileName.split('.').shift() + '.' + asset.md5Hex.substr(0, 10) + asset.extension + asset.url.replace(/^[^#\?]*(?:)/, ''); // Preserve query string and fragment identifier
}
})
return targetUrl + asset.fileName.split('.').shift() + '.' + asset.md5Hex.substr(0, 10) + asset.extension + asset.url.replace(/^[^#\?]*(?:)/, ''); // Preserve query string and fragment identifier
})
.if(options.gzip)
.gzip({isInline: false, isText: true, isLoaded: true, url: query.not(/\.t?gz([\?#]|$)/)})
.endif()
Expand Down

0 comments on commit c5ad4f6

Please sign in to comment.