mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
Improved download speed of js and css files
This commit is contained in:
parent
de2cd51915
commit
61c220ca66
8 changed files with 124 additions and 29 deletions
|
|
@ -114,6 +114,11 @@ set enveronment varibles "oauth_client_id" and
|
|||
|
||||
* Improved reading file with streams.
|
||||
|
||||
* Improved download speed of js and css files by
|
||||
adding DOM.anyLoadInParallel function that is
|
||||
loading files in parallel and then execute
|
||||
callback function.
|
||||
|
||||
|
||||
2012.10.01, Version 0.1.7
|
||||
|
||||
|
|
|
|||
|
|
@ -269,6 +269,50 @@ var CloudCommander, Util, DOM, CloudFunc;
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* improve callback of funcs so
|
||||
* we pop number of function and
|
||||
* if it's last we call pCallBack
|
||||
*
|
||||
* @param pParams_a
|
||||
* @param pFunc - onload function
|
||||
*/
|
||||
DOM.anyLoadInParallel = function(pParams_a, pFunc){
|
||||
var lRet = Util.isArray(pParams_a),
|
||||
done = [],
|
||||
|
||||
doneFunc = function (pCallBack){
|
||||
Util.exec(pCallBack);
|
||||
|
||||
if( !done.pop() )
|
||||
Util.exec(pFunc);
|
||||
};
|
||||
|
||||
if(!lRet){
|
||||
pParams_a = [pParams_a];
|
||||
}
|
||||
|
||||
for(var i = 0, n = pParams_a.length; i < n; i++){
|
||||
var lParam = pParams_a.pop();
|
||||
|
||||
if(lParam){
|
||||
done.push(i);
|
||||
|
||||
if(Util.isString(lParam) )
|
||||
lParam = { src : lParam };
|
||||
|
||||
var lFunc = lParam.func;
|
||||
lParam.func = Util.retExec(doneFunc, lFunc);
|
||||
|
||||
DOM.anyload(lParam);
|
||||
|
||||
lRet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
/**
|
||||
* Функция создаёт элемент и загружает файл с src.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -85,18 +85,20 @@ var CloudCommander, Util, DOM, CloudFunc, CodeMirror;
|
|||
console.time('codemirror load');
|
||||
var lDir = cloudcmd.LIBDIRCLIENT + 'editor/codemirror/';
|
||||
|
||||
DOM.anyLoadOnLoad([
|
||||
lDir + 'codemirror.css',
|
||||
lDir + 'theme/night.css',
|
||||
lDir + 'mode/javascript.js',
|
||||
lDir + 'codemirror.js'],
|
||||
|
||||
function(){
|
||||
console.timeEnd('codemirror load');
|
||||
CodeMirrorLoaded = true;
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
);
|
||||
DOM.jsload(lDir + 'codemirror.js', function(){
|
||||
DOM.anyLoadInParallel([
|
||||
lDir + 'codemirror.css',
|
||||
lDir + 'theme/night.css',
|
||||
lDir + 'mode/javascript.js',
|
||||
],
|
||||
|
||||
function(){
|
||||
console.timeEnd('codemirror load');
|
||||
CodeMirrorLoaded = true;
|
||||
Util.exec(pCallBack);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -105,10 +105,10 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
*/
|
||||
function load(pCallBack){
|
||||
console.time('menu load');
|
||||
|
||||
|
||||
var lDir = Menu.dir;
|
||||
|
||||
DOM.anyLoadOnLoad([
|
||||
DOM.anyLoadInParallel([
|
||||
lDir + 'contextMenu.js',
|
||||
lDir + 'contextMenu.css'],
|
||||
function(){
|
||||
|
|
|
|||
|
|
@ -29,16 +29,17 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
console.time('github load');
|
||||
|
||||
var lDir = './lib/client/storage/github/';
|
||||
DOM.anyLoadOnLoad([
|
||||
lDir + 'github.js',
|
||||
lDir + 'lib/base64.js',
|
||||
lDir + 'lib/underscore.js'],
|
||||
|
||||
function(){
|
||||
console.timeEnd('github load');
|
||||
DOM.Images.hideLoad();
|
||||
DOM.jsload(lDir + 'github.js', function(){
|
||||
DOM.anyLoadOnLoad([
|
||||
lDir + 'lib/base64.js',
|
||||
lDir + 'lib/underscore.js'],
|
||||
|
||||
Util.exec(pCallBack);
|
||||
function(){
|
||||
console.timeEnd('github load');
|
||||
DOM.Images.hideLoad();
|
||||
|
||||
Util.exec(pCallBack);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ var CloudCommander, Util, DOM, $;
|
|||
console.time('terminal load');
|
||||
|
||||
var lDir = 'lib/client/terminal/jquery-terminal/jquery.';
|
||||
DOM.cssLoad(lDir + 'terminal.css');
|
||||
|
||||
DOM.anyLoadOnLoad([
|
||||
DOM.anyLoadInParallel([
|
||||
lDir + 'terminal.js',
|
||||
lDir + 'mousewheel.js'],
|
||||
lDir + 'mousewheel.js',
|
||||
lDir + 'terminal.css'],
|
||||
|
||||
function(){
|
||||
console.timeEnd('terminal load');
|
||||
|
|
|
|||
|
|
@ -98,7 +98,8 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
console.time('fancybox load');
|
||||
var lDir = cloudcmd.LIBDIRCLIENT + 'viewer/fancybox/';
|
||||
|
||||
DOM.anyLoadOnLoad([
|
||||
|
||||
DOM.anyLoadInParallel([
|
||||
lDir + 'jquery.fancybox.css',
|
||||
lDir + 'jquery.fancybox.js'],
|
||||
|
||||
|
|
|
|||
46
lib/util.js
46
lib/util.js
|
|
@ -28,8 +28,7 @@ var Util, exports;
|
|||
* @param pName - получает имя файла
|
||||
* @param pExt - расширение
|
||||
*/
|
||||
Util.checkExtension = function(pName, pExt)
|
||||
{
|
||||
Util.checkExtension = function(pName, pExt){
|
||||
/* если длина имени больше
|
||||
* длинны расширения -
|
||||
* имеет смысл продолжать
|
||||
|
|
@ -118,6 +117,49 @@ var Util, exports;
|
|||
Util.removeStr = function(pStr, pSubStr){
|
||||
return pStr.replace(pSubStr,'');
|
||||
};
|
||||
|
||||
/**
|
||||
* invoke a couple of functions in paralel
|
||||
*
|
||||
* @param {Array} pFuncs
|
||||
* @param {function} pCallback
|
||||
*
|
||||
* Example:
|
||||
* i >=0, pFuncs[i] = function(param, callback){}
|
||||
*/
|
||||
Util.paralelExec = function(pFuncs, pCallback){
|
||||
var done = [];
|
||||
|
||||
/* add items to array done*/
|
||||
function addFunc(pNum){
|
||||
done.push(pNum);
|
||||
}
|
||||
|
||||
/*
|
||||
* improve callback of funcs so
|
||||
* we pop number of function and
|
||||
* if it's last we call pCallBack
|
||||
*/
|
||||
function doneFunc(pParams){
|
||||
Util.exec(pParams.callback);
|
||||
|
||||
var lNum = done.pop (pParams.number);
|
||||
if(!lNum){
|
||||
Util.exec(pCallback);
|
||||
}
|
||||
}
|
||||
|
||||
for(var i = 0, n = pFuncs.length; i < n; i++){
|
||||
addFunc(i);
|
||||
|
||||
var lFunc = pFuncs[i].callback;
|
||||
|
||||
pFuncs[i].callback = Util.retExec(doneFunc, {
|
||||
number : i,
|
||||
callback : lFunc
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is pVarible is array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue