Skip to content

Commit

Permalink
Merge branch 'master' of github.com:seajs/seajs
Browse files Browse the repository at this point in the history
  • Loading branch information
lifesinger committed Mar 25, 2013
2 parents eb254e7 + bb2b051 commit 809da93
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/plugins/plugin-combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,42 @@
//
function paths2hash(paths) {
var comboSyntax = configData.comboSyntax || ["??", ","]

forEach(paths, function(path) {
var root = path[0] + "/"
var group = files2group(path[1])

forEach(group, function(files) {
var comboPath = root + comboSyntax[0] + files.join(comboSyntax[1])

// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url
if (comboPath.length > 2000) {
throw new Error("The combo url is too long: " + comboPath)
}

forEach(files, function(part) {
comboHash[root + part] = comboPath
})
parseComboHash(root, files, comboSyntax)
})

})

return comboHash
}

function parseComboHash(root, files, comboSyntax){
var comboPath = root + comboSyntax[0] + files.join(comboSyntax[1])

// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url
if (comboPath.length > 2000) {
var halfFiles = halfArray(files)

parseComboHash(root, halfFiles[0], comboSyntax)
parseComboHash(root, halfFiles[1], comboSyntax)
//throw new Error("The combo url is too long: " + comboPath)
} else {
forEach(files, function(part) {
comboHash[root + part] = comboPath
})
}
}

var halfArray = function(arr){
var cloneArr = arr.concat();

return [cloneArr.splice(0, Math.ceil(arr.length/2)), cloneArr];
}

//
// ["a.js", "c/d.js", "c/e.js", "a.css", "b.css", "z"]
Expand Down

0 comments on commit 809da93

Please sign in to comment.