diff --git a/public/templates/header.tpl b/public/templates/header.tpl index decbae43da..56bfc48638 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -28,7 +28,6 @@ - diff --git a/src/meta.js b/src/meta.js index b8c12a0721..2108cc277c 100644 --- a/src/meta.js +++ b/src/meta.js @@ -250,6 +250,7 @@ var fs = require('fs'), jsPaths = scripts.map(function (jsPath) { jsPath = path.normalize(jsPath); + // The filter:scripts.get plugin will be deprecated as of v0.5.0, specify scripts in plugin.json instead if (jsPath.substring(0, 7) === 'plugins') { var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { if (jsPath.match(mappedPath)) { @@ -271,15 +272,18 @@ var fs = require('fs'), } }); + // Remove scripts that could not be found (remove this line at v0.5.0) Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); - if (process.env.NODE_ENV !== 'development') { - callback(null, [ - Meta.js.minFile - ]); - } else { - callback(null, scripts); - } + // Add socket.io client library + Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); + + // Add plugin scripts + Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts); + + callback(null, [ + Meta.js.minFile + ]); }); }, minify: function (callback) { @@ -294,6 +298,22 @@ var fs = require('fs'), minified = uglifyjs.minify(jsPaths); this.cache = minified.code; callback(); + }, + compress: function(callback) { + var uglifyjs = require('uglify-js'), + jsPaths = this.scripts, + compressed; + + if (process.env.NODE_ENV === 'development') { + winston.info('Compressing client-side libraries into one file'); + } + + minified = uglifyjs.minify(jsPaths, { + mangle: false, + compress: false + }); + this.cache = minified.code; + callback(); } }; diff --git a/src/plugins.js b/src/plugins.js index f334d8b0da..c704049641 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -17,6 +17,7 @@ var fs = require('fs'), Plugins.staticDirs = {}; Plugins.cssFiles = []; Plugins.lessFiles = []; + Plugins.clientScripts = []; Plugins.initialized = false; diff --git a/src/routes/meta.js b/src/routes/meta.js index 0900ca07d8..0a09074b2c 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -45,12 +45,22 @@ var path = require('path'), }); app.get('/nodebb.min.js', function(req, res) { + var sendCached = function() { + return res.type('text/javascript').send(meta.js.cache); + } if (meta.js.cache) { - res.type('text/javascript').send(meta.js.cache); + sendCached(); } else { - meta.js.minify(function() { - res.type('text/javascript').send(meta.js.cache); - }); + if (app.enabled('minification')) { + meta.js.minify(function() { + sendCached(); + }); + } else { + // Compress only + meta.js.compress(function() { + sendCached(); + }); + } } }); };