Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 749
FutuToad Avatar asked Mar 01 '13 10:03

FutuToad


People also ask

What bundle would you use to minify CSS and/or javascript on a production environment?

Click on wwwroot folder, select the css file you want minified, then right click and choose bundler & minifier. Then from popup minify file. It will be the same file name with the minified version.

How will you implement bundling and minification in MVC?

To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.

What is difference between bundling and minification?

Both bundling and minification are the two separate techniques to reduce the load time. The bundling reduces the number of requests to the Server, while the minification reduces the size of the requested assets.

How do I bundle a Javascript file in .NET core?

In this article, we will add bundling in our existing web application developed in . NET CORE MVC. Firstly you have to add Bundler and Minifier extension in your project as show below by clicking on the extension menu. After adding an extension please restart the Visual Studio so that the extension will load.


Video Answer


1 Answers

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)

like image 114
Bart Verkoeijen Avatar answered Oct 13 '22 00:10

Bart Verkoeijen