Skip to content

Commit

Permalink
report on # characters removed
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Nov 25, 2012
1 parent 85119df commit e885c35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/browser.js
Expand Up @@ -279,30 +279,32 @@ 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';
xhr.send();
}

// 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) {
executableScripts[i++].type = 'asterisk/ignore';
}
}

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);
Expand All @@ -316,6 +318,7 @@ function asteriskMinify (messagePrefix, exitMessage, config, inspect) {
}

console.log(messagePrefix, JSON.stringify({
original: originalMarkup,
html: output,
iScripts: inlineScripts,
iStyles: inlineStyles,
Expand Down
6 changes: 3 additions & 3 deletions src/server.js
Expand Up @@ -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');
}
};

Expand Down

0 comments on commit e885c35

Please sign in to comment.