Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET bundle does not work when deployed (debug="false")

In development bundling works as expected with uncombined and unminified files but after deploying a site with web.config set enable the bundles

<compilation debug="false" targetFramework="4.5" />

the result of get a request to a bundle may include a comment at the top similar to the following

/* Minification failed. Returning unminified contents.
.. errors like JS1002 or JSxxxx errors

In other cases no errors are thrown from minification but some javascripts fails to run or errors during execution.

What syntax in otherwise working javascript might cause this behavior after bundling?

like image 710
Keith Lawrence Avatar asked Jan 08 '13 21:01

Keith Lawrence


1 Answers

One situation that can cause this is a single line comment // as the last line of a javascript file. This will cause the next file appened to have at least the first line also commented out

if forexample you have a bundle

bundles.Add(New ScriptBundle("~/bundles/test").Include(
            "~/Scripts/adder.js",
            "~/Scripts/printer.js"))

adder.js

function adder(a, b) {
    return a + b;
}
//this is the adder.js

printer.js

printer = true;

if (printer) {
    alert("It works");
    document.getElementById("itWorked").textContent = "It worked";    
}
like image 142
Keith Lawrence Avatar answered Oct 31 '22 21:10

Keith Lawrence