Running an ASP.NET MVC 4 app in release mode does not bundle and minifiy the js files

FutuToad picture FutuToad · Mar 1, 2013 · Viewed 7.7k times · Source

When I run my ASP.NET MVC 4 app in release mode, the bundles are still outputting the unminified and separate js files, instead of bundling and minifying it into fewer bundled JavaScript files.

Any ideas?

FYI, release config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

Answer

Bart Verkoeijen picture Bart Verkoeijen · Jun 30, 2013

Thanks to aleyush's comment that Web.release.config is only used during publishing the app, and not when running it locally, I was able to fix it by adding the following lines to the BundleConfig.cs file:

#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif

Since Debug mode will define the DEBUG constant, and during Release mode it is not defined, this line will only execute during Release mode. (you can test it by setting a breakpoint)