diff --git a/cli/index.js b/cli/index.js index eb23af3..3f96d87 100755 --- a/cli/index.js +++ b/cli/index.js @@ -53,6 +53,10 @@ function main() { pkg: defaults(pkg, { version: '0.0.0' }), }).notify(); + inliner.on('warning', function progress(event) { + console.warn('warning: ' + event); + }); + if (argv.verbose) { inliner.on('progress', function progress(event) { console.error(event); diff --git a/lib/get.js b/lib/get.js index c768d32..a9d214e 100644 --- a/lib/get.js +++ b/lib/get.js @@ -7,6 +7,7 @@ var mime = require('mime'); var cache = {}; module.exports = function get(url, options) { + var inliner = this; if (url.indexOf('data:') === 0) { debug('asset already inline', url); return Promise.resolve({ @@ -61,6 +62,7 @@ module.exports = function get(url, options) { debug('response: %s %s', res.statusCode, url); if (res.statusCode !== 200) { body = ''; + inliner.emit('warning', res.statusCode + ' on ' + url); } resolve({ diff --git a/lib/index.js b/lib/index.js index 85f8944..70cd351 100644 --- a/lib/index.js +++ b/lib/index.js @@ -146,10 +146,6 @@ function main() { var cheerioLoadOptions = {}; var enc = inliner.options.encoding; - if (res.statusCode !== 200) { - inliner.emit('progress', res.statusCode + ' on ' + url); - } - // try to determine the encoding from the headers and the body if (!enc) { enc = charset(res.headers, res.body); diff --git a/lib/javascript.js b/lib/javascript.js index bd3b8b3..3934565 100644 --- a/lib/javascript.js +++ b/lib/javascript.js @@ -6,16 +6,17 @@ var UglifyJS = require('uglify-js'); function uglify(source) { this.emit('progress', 'compressing javascript'); - if (source.body === '') { - return ''; - } - - if (source.body) { + if (source.body !== undefined) { source = source.body; } // in case of local buffer source = source.toString(); + + if (source.trim() === '') { + return ''; + } + debug('uglifying %sbytes', source.length); return UglifyJS.minify(source, {