From e885c35b1ebbfcf09ed6bbdd2c8fb778af4d50b6 Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Sun, 25 Nov 2012 19:38:25 +0000 Subject: [PATCH] report on # characters removed --- src/browser.js | 13 ++++++++----- src/server.js | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/browser.js b/src/browser.js index 4984d0f..6d37b8a 100644 --- a/src/browser.js +++ b/src/browser.js @@ -279,7 +279,7 @@ function asteriskMinify (messagePrefix, exitMessage, config, inspect) { xhr.onload = function(evnt) { var _document = document.implementation.createHTMLDocument('no-js'); _document.documentElement.innerHTML = xhr.responseText; - onComplete(_document); + onComplete(_document, xhr.responseText); }; xhr.open('GET', location.href); xhr.responseType = 'text'; @@ -287,11 +287,12 @@ function asteriskMinify (messagePrefix, exitMessage, config, inspect) { } // begin - getNonJsMarkup(function(_document) { + getNonJsMarkup(function(_document, originalMarkup) { var i = 0; var executableScripts = _document.querySelectorAll('script:not([type]),script[type="text/javascript"]'); var len = executableScripts.length; var root = document.documentElement; + var docType = getDocType() +'\n'; if(len) { while(i < len) { @@ -299,10 +300,11 @@ function asteriskMinify (messagePrefix, exitMessage, config, inspect) { } } - document.documentElement.replaceChild(_document.querySelector('head'), document.querySelector('head')); - document.documentElement.replaceChild(_document.querySelector('body'), document.querySelector('body')); + root.replaceChild(_document.querySelector('head'), document.querySelector('head')); + root.replaceChild(_document.querySelector('body'), document.querySelector('body')); + _document = null; - output.push(getDocType() +'\n'); + output.push(docType); if (inspect) { inspectLayout(root, layoutBefore); @@ -316,6 +318,7 @@ function asteriskMinify (messagePrefix, exitMessage, config, inspect) { } console.log(messagePrefix, JSON.stringify({ + original: originalMarkup, html: output, iScripts: inlineScripts, iStyles: inlineStyles, diff --git a/src/server.js b/src/server.js index 4e5e48f..9a99133 100644 --- a/src/server.js +++ b/src/server.js @@ -95,11 +95,11 @@ exports.failMessage = exports.report.bind(exports, 31, '✘'); * @return {[type]} [description] */ exports.reportOnInspection = function(output) { - var msg = ' elements with layout unaffected after minification'; + var msg = (output.original.length - output.html.join('').length) + ' characters removed, ' + output.count + ' elements with layout unaffected by minification'; if(exports.layoutIsIntact(output)) { - exports.successMessage(output.count + msg); + exports.successMessage(msg); } else { - exports.failMessage(output.count + msg + '\n- Please report the issue with this URL via the issues page at https://github.com/JamieMason/Asterisk/issues/new'); + exports.failMessage(msg + '\n- Please report the issue with this URL via the issues page at https://github.com/JamieMason/Asterisk/issues/new'); } };