scrat-swig
Advanced tools
Comparing version 0.6.0 to 0.7.0
0.7.0 / 2016-04-08 | ||
================== | ||
* [UPD] combo url的max length如果没传,默认是正无穷 | ||
* [UPD] 增加combo url长度配置参数,默认参数长度为1920。支持将combo请求切换为多个。 (解决局部地区运营商对url param做了长度限制的坑) | ||
0.6.0 / 2016-03-27 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var DEFAULT_COMBO_PATTERN = '/co??%s'; | ||
var DEFAULT_COMBO_MAX_LENGTH = Number.POSITIVE_INFINITY; // 正无穷 | ||
var PREFIX = 'components'; | ||
@@ -233,9 +234,21 @@ var options = null; | ||
*/ | ||
Resource.prototype.genComboURI = function(collect) { | ||
Resource.prototype.genComboURI = function(collect, urlLength) { | ||
var url = this.getComboPattern(); | ||
var len = typeof(urlLength) !== 'undefined' ? urlLength : DEFAULT_COMBO_MAX_LENGTH; // best length 1920 = 1024 + 512 + 256 + 128 | ||
var output = []; | ||
var combo = ''; | ||
var temp; | ||
collect.forEach(function(uri) { | ||
combo += ',' + this.comboURI(uri); | ||
temp = ',' + this.comboURI(uri); | ||
if (!combo.length || [combo, temp].join('').length <= len) { | ||
combo += temp; | ||
} else { | ||
output.push(url.replace('%s', combo.substring(1))); | ||
combo = temp; | ||
} | ||
}, this); | ||
return url.replace('%s', combo.substring(1)); | ||
output.push(url.replace('%s', combo.substring(1))); | ||
return output; | ||
}; | ||
@@ -282,3 +295,6 @@ | ||
if (options.combo) { | ||
html += left + this.genComboURI(this._collect.js) + right; | ||
var pack = this.genComboURI(this._collect.js, options.comboMaxLen); | ||
pack.forEach(function(res) { | ||
html += left + res + right; | ||
}); | ||
} else { | ||
@@ -324,3 +340,6 @@ html += join(this._collect.js, left, right); | ||
if (options.combo) { | ||
html += left + this.genComboURI(collect) + right; | ||
var pack = this.genComboURI(collect, options.comboMaxLen); | ||
pack.forEach(function(res) { | ||
html += left + res + right; | ||
}); | ||
} else { | ||
@@ -327,0 +346,0 @@ html += join(collect, left, right); |
{ | ||
"name": "scrat-swig", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Extensions of swig for scrat", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
41625
1054