UPDATE
Checking once more your code, there is a bunch of repeted code you should turn into methods. For instance, this whole part
var dir = "";
if (typeof source[i].dir == "undefined") {
// default = js-common
dir = sourceFiles.staticJsCommon();
} else if (typeof source[i].dir == "js-common") {
dir = sourceFiles.staticJsCommon();
} else if (typeof source[i].dir == "css-common") {
dir = sourceFiles.staticCssCommon();
} else if (typeof source[i].dir == "img-common") {
dir = sourceFiles.staticImgCommon();
}
should become one method with one param
var dir = sourceFiles.handleFileDir(source[i].dir)
and all the methods below
staticRoot : function () {
if (typeof $ms.STATIC_TOP_ROOT !== "undefined") {
return $ms.STATIC_TOP_ROOT;
} else {
return window.location.origin ? window.location.origin + '/' : window.location.protocol + '/' + window.location.host;
}
},
staticJsCommon : function () {
if (typeof $ms.STATIC_JS_COMMON !== "undefined") {
return $ms.STATIC_JS_COMMON;
} else {
return window.location.origin ? window.location.origin + '/' : window.location.protocol + '/' + window.location.host + "/js-common";
}
},
staticImgCommon : function () {
if (typeof $ms.STATIC_IMG_COMMON !== "undefined") {
return $ms.STATIC_IMG_COMMON;
} else {
return window.location.origin ? window.location.origin + '/' : window.location.protocol + '/' + window.location.host + "/img-common";
}
}
are really only one method. Could be something like
handleFileDir : function (pathPart) {
// decide on type ref and define the var
var typeToCheck = function (_path) {
if (_path.indexOf("js") > -1) return "STATIC_JS_COMMON";
if (_path.indexOf("css") > -1) return "STATIC_CSS_COMMON";
if (_path.indexOf("img") > -1) return "STATIC_IMG_COMMON";
return "STATIC_TOP_ROOT";
}(pathPart);
if (typeof $ms[typeToCheck] !== "undefined") {
return $ms[typeToCheck];
} else {
return window.location.origin ? window.location.origin + '/' : window.location.protocol + '/' + window.location.host + pathPart;
}
}
Always be suspicious of code smell when parts of your code look alike so much...