Comparing version 0.1.2 to 0.1.3
@@ -140,7 +140,5 @@ var path = require('path'); | ||
var addedAsync = { | ||
async:true | ||
}; | ||
var addedSync = { | ||
sync:true | ||
}; | ||
@@ -154,2 +152,7 @@ | ||
var changed = false; | ||
var usedPkg = {}; | ||
var usedSync= {}; | ||
/** | ||
@@ -170,2 +173,5 @@ * 获取同步资源依赖 | ||
var dep = fis.getInfo(depId, true); | ||
if (dep.type !== 'js' && dep.type !== 'css'){ | ||
return; | ||
} | ||
dep.id = depId; | ||
@@ -199,2 +205,5 @@ if (!dep){ | ||
var dep = fis.getInfo(depId, true); | ||
if (dep.type !== 'js' && dep.type !== 'css'){ | ||
return; | ||
} | ||
dep.id = depId; | ||
@@ -213,2 +222,5 @@ if (!dep){ | ||
async.id = asyncId; | ||
if (async.type !== 'js' && async.type !== 'css'){ | ||
return; | ||
} | ||
if (!async){ | ||
@@ -228,2 +240,3 @@ return false; | ||
if (file){ | ||
changed = true; | ||
file.id = id; | ||
@@ -233,3 +246,5 @@ var depList = getDepList(file, addedSync); | ||
syncs = syncs.concat(depList); | ||
syncs.push(file); | ||
if (file.type === 'js' || file.type === 'css'){ | ||
syncs.push(file); | ||
} | ||
asyncs = asyncs.concat(asyncList); | ||
@@ -270,2 +285,3 @@ } | ||
addJs: function(url) { | ||
changed = true; | ||
var info = fis && fis.getInfo(url, true); | ||
@@ -285,9 +301,4 @@ | ||
getJs: function() { | ||
var js = []; | ||
syncs.forEach(function(item){ | ||
if (item.type === 'js'){ | ||
js.push(item.uri); | ||
} | ||
}); | ||
return js; | ||
this.preparePageResource(); | ||
return jsList; | ||
}, | ||
@@ -312,2 +323,3 @@ | ||
addCss: function(url) { | ||
changed = true; | ||
var info = fis && fis.getInfo(url, true); | ||
@@ -327,9 +339,4 @@ | ||
getCss: function() { | ||
var css = []; | ||
syncs.forEach(function(item){ | ||
if (item.type === 'css'){ | ||
css.push(item.uri); | ||
} | ||
}); | ||
return css; | ||
this.preparePageResource(); | ||
return cssList; | ||
}, | ||
@@ -383,2 +390,8 @@ | ||
preparePageResource: function(){ | ||
//检查preparePageResource后是否还有资源修改,如果没有修改则无需优化 | ||
if (!changed){ | ||
return; | ||
} | ||
changed = false; | ||
//生成同步资源引用列表 | ||
var depList = syncs; | ||
@@ -394,7 +407,7 @@ asyncs = asyncs.filter(function (async, index) { | ||
//生成同步资源引用列表 | ||
var usedPkg = {}; | ||
var usedSync= {}; | ||
depList.forEach(function (dep) { | ||
var res = dep; | ||
if (usedSync[res.id]){ | ||
return; | ||
} | ||
usedSync[res.id] = true; | ||
@@ -417,4 +430,2 @@ if (res.pkg){ | ||
}); | ||
asyncs = asyncs.filter(function (async, index) { | ||
@@ -479,12 +490,6 @@ //剔除同步资源 | ||
this.preparePageResource(); | ||
content = this.filterJs(content); | ||
if(~content.indexOf(this.JS_HOOK)) { | ||
content = this.filterJs(content); | ||
} | ||
content = this.filterCss(content); | ||
if(~content.indexOf(this.CSS_HOOK)) { | ||
content = this.filterCss(content); | ||
} | ||
return content; | ||
@@ -495,2 +500,4 @@ }, | ||
this.preparePageResource(); | ||
var resourceMap = this.getResourceMap(); | ||
@@ -519,2 +526,5 @@ var scripts = this.getScripts(); | ||
filterCss: function(content) { | ||
this.preparePageResource(); | ||
var styles = this.getStyles(); | ||
@@ -521,0 +531,0 @@ var csses = cssList; |
{ | ||
"name": "yog-view", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "An express.js middleware for optimizing the order of js\\css output, and enabling render template in bigpipe mode.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
23023
8
564