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?
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With