From 1c8f70fae91892f6e3327dc80202daecd61d69bd Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sun, 24 Jul 2011 20:18:47 +0100 Subject: [PATCH] Disabling minify creates now one big js file, instead of loading js files dynamicly. This solves problems we had with random loading of the js files --- node/minify.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/node/minify.js b/node/minify.js index 54fe18483..e438de229 100644 --- a/node/minify.js +++ b/node/minify.js @@ -228,24 +228,34 @@ exports.padJS = function(req, res) res.sendfile(pathStr, { maxAge: server.maxAge }); }) } - //minifying is disabled, so load the files with jquery + //minifying is disabled, so put the files together in one file else { - res.write("function loadjsfile(filename){\n"+ - "var fileref=document.createElement('script');\n"+ - "fileref.setAttribute('type','text/javascript');\n"+ - "var path = 'static/js/' + filename;\n"+ - "fileref.setAttribute('src', path);\n" + - "document.getElementsByTagName('head')[0].appendChild(fileref);\n" + - "}\n"); + var fileValues = {}; - for(var i in jsFiles) + //read all js files + async.forEach(jsFiles, function (item, callback) { - console.log(jsFiles[i]); - res.write("loadjsfile('"+ jsFiles[i] + "');\n"); - } - - res.end(); + fs.readFile("../static/js/" + item, "utf-8", function(err, data) + { + fileValues[item] = data; + callback(err); + }); + }, + //send all files together + function(err) + { + if(err) throw err; + + for(var i=0;i