Merge pull request +7862 from c9/parallel-requests

More parallel requests + caching for unpacked (online)dev
pull/117/merge
Harutyun Amirjanyan 2015-07-07 17:30:52 +04:00
commit e48310adfd
3 zmienionych plików z 63 dodań i 0 usunięć

Wyświetl plik

@ -302,6 +302,9 @@ module.exports = function(options) {
{
packagePath: "plugins/c9.ide.language/language",
workspaceDir: workspaceDir,
staticPrefix: options.packed
? staticPrefix
: options.ideBaseUrl + "/uph" + staticPrefix,
workerPrefix: options.CORSWorkerPrefix // "/static/standalone/worker"
},
"plugins/c9.ide.language/keyhandler",

Wyświetl plik

@ -274,6 +274,9 @@ var config = require.config = function(cfg) {
cfg.paths && Object.keys(cfg.paths).forEach(function(p) {
config.paths[p] = cfg.paths[p];
});
if (cfg.baseUrlLoadBalancers)
config.baseUrlLoadBalancers = cfg.baseUrlLoadBalancers;
};
config.packages = Object.create(null);
config.paths = Object.create(null);
@ -322,9 +325,24 @@ require.toUrl = function(moduleName, ext, skipExt) {
if (!absRe.test(url)) {
url = (config.baseUrl || require.MODULE_LOAD_URL + "/") + url;
}
if (url[0] === "/" && config.baseUrlLoadBalancers) {
var n = Math.abs(hashCode(url)) % config.baseUrlLoadBalancers.length;
url = config.baseUrlLoadBalancers[n] + url;
}
return url;
};
function hashCode(string) {
var result = 0, i, chr, len;
if (string.length == 0) return result;
for (i = 0, len = string.length; i < len; i++) {
chr = string.charCodeAt(i);
result = ((result << 5) - result) + chr;
result |= 0; // Convert to 32bit integer
}
return result;
}
var loadScript = function(path, id, callback) {
// TODO use importScripts for webworkers
var head = document.head || document.documentElement;

Wyświetl plik

@ -0,0 +1,42 @@
"use strict";
plugin.consumes = [
"db", "connect.static"
];
plugin.provides = [
"unpacked_helper"
];
module.exports = plugin;
function plugin(options, imports, register) {
var connectStatic = imports["connect.static"];
var assert = require("assert");
var baseUrl = options.baseUrl;
var ideBaseUrl = options.ideBaseUrl;
assert(baseUrl, "baseUrl must be set");
assert(ideBaseUrl, "ideBaseUrl must be set");
var balancers = [
baseUrl + "/uph",
];
/* UNDONE: for now we put all static content on one domain
because of reports of CORS errors
if (!options.avoidSubdomains)
balancers.push(
ideBaseUrl
// We could include others but dogfooding URLs like
// vfs.newclient-lennartcl.c9.io don't have a cert, so
// let's not
// apiBaseUrl + "/uph",
// vfsBaseUrl + "/uph"
);
*/
connectStatic.getRequireJsConfig().baseUrlLoadBalancers = balancers;
assert(connectStatic.getRequireJsConfig().baseUrlLoadBalancers);
register(null, {
"unpacked_helper": {}
});
}