JQuery crash due to minifying packages in release mode
I have a jquery package:
bundles.Add(new ScriptBundle("~/bundle/jquery").Include(
ScriptsPath("jquery-2.0.3.js"),
ScriptsPath("jquery.validate.js"),
ScriptsPath("jquery.validate.unobtrusive.js"),
ScriptsPath("jquery-ui-1.10.3.js"),
ScriptsPath("jquery.validate.unubtrusive.config.js"),
ScriptsPath("jquery.easing.1.3.js "),
ScriptsPath("jquery.unobtrusive-ajax.min.js"),
ScriptsPath("jquery.validate.custom.attributes.js") ...
On the user registration page, I have both the registration and the registration form, so the name of the form there Register.
and Login.
prefixes in their names. It basically looks like this:
<input type="text" ... id="Register_Email" name="Register.Email" />
<input type="password" ... id="Register_Password" name="Register.Password" />
When I publish my app in release mode, I get this error in the bundle file:
This is obviously because of the dot in the input name. How to keep the point and fix this problem? I have already tried BundleTable.EnableOptimizations = false;
it but it didnโt help and I donโt think this is a suitable solution because it invalidates the package target. Also note that the issue only occurs in Release mode .
edits:
The Bundle File List contains one native script file, it contains the client side validation logic for mine ForbidHtmlAttribude
:
jquery.validate.custom.attributes.js
jQuery.validator.unobtrusive.adapters.add(
'forbidhtmlattribute',
['htmlregexpattern'],
function (options) {
options.rules['forbidhtmlattribute'] = options.params;
options.messages['forbidhtmlattribute'] = options.message;
}
);
jQuery.validator.addMethod('forbidhtmlattribute', function (value, element, params) {
if (value === null || value === undefined) return true;
var regex = params['htmlregexpattern'];
return !value.match(regex);
}, '');
source to share
Most likely the problem is on this line:
if (value === null || value === undefined) return true;
Try changing it to
if ((value === null) || (value === undefined)) return true;
Exaplanation:
MS minimization algorithm removes unnecessary spaces. It "knows" language keywords like "var" or "return", but "null" is not one of them. So the miniature string would be
if(value===null||value===undefined)return true;
Now, from a JavaScript point of view, we have a strange variable called " null||value
". Including conditions in parentheses solves the problem:
if(value===null)||(value===undefined)return true;
source to share