From cc31dc3b41a5cdb31f8e3ebf1d38dd3230252b6f Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 10 Jul 2012 09:07:02 -0400 Subject: [PATCH] Added ability to read file data from Minify Cache, without writing to disk --- ChangeLog | 4 +++- lib/server/minify | 2 +- server.js | 58 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8af8c533..7050e4eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,4 +12,6 @@ return final_code so changes was not saving, and clien side loaded keyBinding.js and cloudfunc.js full sized versions. * Changed the way Minify post-processing js-files so, from now in Minify object -post-processing functions passed like this {'client.js': function(){}} \ No newline at end of file +post-processing functions passed like this {'client.js': function(){}} + +* Added ability to read file data from Minify Cache, without writing to disk \ No newline at end of file diff --git a/lib/server/minify b/lib/server/minify index 080b6e74..04d536b9 160000 --- a/lib/server/minify +++ b/lib/server/minify @@ -1 +1 @@ -Subproject commit 080b6e746f773649fd06aa113a2298fa285478c3 +Subproject commit 04d536b9941088ef25294a03e0ca75047dd30131 diff --git a/server.js b/server.js index b3261a4e..e474bde6 100644 --- a/server.js +++ b/server.js @@ -189,7 +189,7 @@ CloudServer.Minify={ .replace('/lib/', lMinFolder) .replace('/lib/client/', lMinFolder)).length); return pFinalCode; - }}) + }},true) :false; this.done.html=this._allowed.html? @@ -198,14 +198,17 @@ CloudServer.Minify={ this.done.css=this._allowed.css? lMinify.cssStyles([CloudServer.CSSDIR + '/style.css', CloudServer.CSSDIR + '/reset.css'], - this._allowed.img):false; + this._allowed.img):false; + + this.Cache = lMinify.Cache; } }), /* свойство показывающее случилась ли ошибка*/ done:{js: false,css: false, html:false}, /* minification folder name */ - MinFolder:'' + MinFolder :'', + Cache :{} }; @@ -276,7 +279,7 @@ CloudServer.init=(function(){ */ CloudServer.Minify.setAllowed(CloudServer.Config.minification); /* Если нужно минимизируем скрипты */ - CloudServer.Minify.doit(); + CloudServer.Minify.doit(); }); @@ -435,18 +438,43 @@ CloudServer._controller=function(pReq, pRes) * не сжатый - в обратном случае */ var lFileData=CloudServer.Cache.get(CloudServer.Gzip?(lName+'_gzip'):lName); - + console.log(Path.basename(lName)); + + var lMinify=CloudServer.Minify; + + /* object thet contains information + * about the source of file data + */ + var lFromCache_o={'cache': true}; + + /* if cache is empty and Cache allowed and Minify_allowed + * and in Minifys cache is files, so save it to + * CloudServer cache + */ + if(!lFileData && + lMinify._allowed){ + console.log('trying to read data from Minify.Cache'); + lFromCache_o.cache=false; + lFileData = CloudServer.Minify.Cache[ + Path.basename(lName)]; + } var lReadFileFunc_f=CloudServer.getReadFileFunc(lName); /* если там что-то есть передаём данные в функцию * readFile */ - if(lFileData){ - console.log('readed from cache'); + if(lFileData){ + /* if file readed not from cache - he readed from minified cache */ + if(lFromCache_o.cache===false) + lFromCache_o.minify=true; + else + lFromCache_o.minify=false; + + console.log(lName + ' readed from cache'); /* передаём данные с кэша, * если gzip включен - сжатые * в обратном случае - несжатые */ - lReadFileFunc_f(undefined,lFileData,true); + lReadFileFunc_f(undefined,lFileData,lFromCache_o); } else Fs.readFile(lName,lReadFileFunc_f); @@ -674,11 +702,13 @@ CloudServer._readDir=function (pError, pFiles) */ CloudServer.getReadFileFunc = function(pName){ /* - * @pError - ошибка - * @pData - данные - * @pFromFile - прочитано с файла bool + * @pError - ошибка + * @pData - данные + * @pFromCache_o - прочитано с файла, + * или из одного из кешей + * Пример {cache: false, minify: true} */ - var lReadFile=function(pError,pData,pFromCache_b){ + var lReadFile=function(pError, pData, pFromCache_o){ if (!pError){ console.log('file ' + pName + ' readed'); @@ -686,7 +716,7 @@ CloudServer.getReadFileFunc = function(pName){ * если их нет в кэше - * сохраняем */ - if(!pFromCache_b && CloudServer.Cache.isAllowed) + if(pFromCache_o && !pFromCache_o.cache && CloudServer.Cache.isAllowed) CloudServer.Cache.set(pName,pData); /* если кэш есть * сохраняем его в переменную @@ -697,7 +727,7 @@ CloudServer.getReadFileFunc = function(pName){ var lHeader=CloudServer.generateHeaders(pName,CloudServer.Gzip); /* если браузер поддерживает gzip-сжатие - сжимаем данные*/ - if(CloudServer.Gzip &&!pFromCache_b){ + if( CloudServer.Gzip && !(pFromCache_o && pFromCache_o.cache) ){ /* сжимаем содержимое */ Zlib.gzip(pData,CloudServer.getGzipDataFunc(lHeader,pName)); }