Monday, March 22, 2010

jscompress fails to compress my js file and errors out - why?

Issue:

You use the online compression utility jscompress.com to compress your js file but it fails with an error. Why this may be happening and how to fix it.

Possible causes:

Apparently not using open and closing curly brackets in an IF statement would cause this. Well turns out this is not the case. Look at the following example and see if you can figure out what the issue is :-)




function SetupDeliveredVPRecontactNotes($item, id) {
var theData;

$.ajax({
data: { deliveredVPId: id },
url: $('#ajaxGetDeliveredVPRecontactNotesUrl').val(),
type: "GET",
async: false,
dataType: "html",
success: function(data, result) {
$item.empty();

var input = '';
$item.append('input');
theData = data;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$item.empty();
alert("An error occurred: The operation to retrieve the DeliveredVP's Recontact Notes has failed");
}
}); //ajax

return theData;
}


Solution:

The issue is the closing textarea tab, concatenate it as

''
will fix the issue

1 comment:

  1. jscompress is outdated and has broken functionality. One should be wary of using it for production code at this point. I have found a similar tool that is regularly updated and all features work. Also updated to UglifyJS2. You can find the free only javascript minify tool at http://www.blimptontech.com

    ReplyDelete