jquery 1.9.0 and modernizr cannot be minified with the ASP.NET Web Optimization Framework

I’m sure that the cause of your problem is the last line of jquery-1.9.0.min.js:

//@ sourceMappingURL=jquery.min.map

The unminified version of jQuery 1.9 does not contain this. I’ll explain why in a minute.

I’ve noticed myself that when jquery-1.9.0.min.js is bundled with another file – and that other file follows jquery-1.9.0.min.js – then the following JS file is, in a manner of speaking, corrupted.

The reason is that the start of the following file is appended to the “//@” line of jQuery, which means that it then becomes one long, extended comment. In your case this meant that the

window.Modernizr=function(n,t,i){function...

script at the start of Modernizr was outputed from the bundling process as a comment like so:

//@ sourceMappingURL=jquery.min.map window.Modernizr=function(n,t,i){function...

There’s a discussion on jQuery’s Bug Tracker regarding this.

Your options are either to remove that last line or to wrap it in multi-line comment symbols:

/*
//@ sourceMappingURL=jquery.min.map
*/

Also, you can see that Modernizr also contains a source map at the end of its minified version. And with good reason.

The rationale behind it is to help you in debugging a problem when the minified version of the code has been used. This line tells the browser that this minified file maps to another file which can aid in debugging. To take advantage of this you need to have that referenced file (jquery.min.map) on the server or downloaded to the client. Plus, I believe that Chrome is the only browser currently supporting this; it’s still under development at Firefox.

This page has an excellent explanation of Source Maps.

So in summary, removing it shouldn’t really cause you any problems unless you wish to map back to the original version of the source while debugging in the browser. In your case, because of the way that ASP.NET’s Optimization Framework works, when debug=”True” it will serve up the unminified versions anyway, so you probably don’t have a need to use the sourceMappingURL.

Leave a Comment