From 9ede14a546731e692640a408c2b5bdb07d2c2c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Sun, 19 Feb 2012 15:02:54 +0100 Subject: [PATCH] drop embedding of JS/CSS files in ace.js. May result in a little performance drop but makes code much smaller --- node/utils/Minify.js | 74 +------------------- static/js/ace.js | 158 +++++++++++++++---------------------------- 2 files changed, 56 insertions(+), 176 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 859ee07a..baeaee68 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -213,72 +213,6 @@ function _handle(req, res, jsFilename, jsFiles) { } } -// find all includes in ace.js and embed them. -function getAceFile(callback) { - fs.readFile(JS_DIR + 'ace.js', "utf8", function(err, data) { - if(ERR(err, callback)) return; - - // Find all includes in ace.js and embed them - var founds = data.match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi); - if (!settings.minify) { - founds = []; - } - founds.push('$$INCLUDE_JS("../static/js/require-kernel.js")'); - - data += ';\n'; - data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n'; - - //go trough all includes - async.forEach(founds, function (item, callback) { - var filename = item.match(/"([^"]*)"/)[1]; - var type = item.match(/INCLUDE_([A-Z]+)/)[1]; - var shortFilename = (filename.match(/^..\/static\/js\/(.*)$/, '')||[])[1]; - - //read the included files - if (shortFilename) { - if (shortFilename == 'require-kernel.js') { - // the kernel isn’t actually on the file system. - handleEmbed(null, requireDefinition()); - } else { - var contents = ''; - tarCode(tar[shortFilename] || shortFilename - , function (content) { - contents += content; - } - , function () { - handleEmbed(null, contents); - } - ); - } - } else { - fs.readFile(ROOT_DIR + filename, "utf8", handleEmbed); - } - - function handleEmbed(error, data_) { - if (error) { - return; // Don't bother to include it. - } - if (settings.minify) { - if (type == "JS") { - try { - data_ = compressJS([data_]); - } catch (e) { - // Ignore, include uncompresseed, which will break in browser. - } - } else { - data_ = compressCSS([data_]); - } - } - data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = ' - + JSON.stringify(data_) + ';\n'; - callback(); - } - }, function(error) { - callback(error, data); - }); - }); -} - exports.requireDefinition = requireDefinition; function requireDefinition() { return 'var require = ' + RequireKernel.kernelSource + ';\n'; @@ -288,12 +222,8 @@ function tarCode(jsFiles, write, callback) { write('require.define({'); var initialEntry = true; async.forEach(jsFiles, function (filename, callback){ - if (filename == 'ace.js') { - getAceFile(handleFile); - } else { - fs.readFile(JS_DIR + filename, "utf8", handleFile); - } - + fs.readFile(JS_DIR + filename, "utf8", handleFile); + function handleFile(err, data) { if(ERR(err, callback)) return; var srcPath = JSON.stringify('/' + filename); diff --git a/static/js/ace.js b/static/js/ace.js index 6c7bb84e..63b1e61f 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -133,74 +133,6 @@ function Ace2Editor() return info.ace_getUnhandledErrors(); }; - - - function sortFilesByEmbeded(files) { - var embededFiles = []; - var remoteFiles = []; - - if (Ace2Editor.EMBEDED) { - for (var i = 0, ii = files.length; i < ii; i++) { - var file = files[i]; - if (Object.prototype.hasOwnProperty.call(Ace2Editor.EMBEDED, file)) { - embededFiles.push(file); - } else { - remoteFiles.push(file); - } - } - } else { - remoteFiles = files; - } - - return {embeded: embededFiles, remote: remoteFiles}; - } - function pushRequireScriptTo(buffer) { - var KERNEL_SOURCE = '../static/js/require-kernel.js'; - var KERNEL_BOOT = 'require.setRootURI("../minified/");\nrequire.setGlobalKeyPath("require");' - if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) { - buffer.push(''); + iframeHTML.push('\ -'); - pushScriptsTo(iframeHTML); - + iframeHTML.push('require.define("/plugins", null);'); + iframeHTML.push('require.define("/plugins.js", function (require, exports, module) {'); + iframeHTML.push('module.exports = parent.parent.require("/plugins");'); + iframeHTML.push('});'); + iframeHTML.push('<\/script>'); + + // Require ace2 + iframeHTML.push(''); + iframeHTML.push('