5

According to documentation in release mode the bundler should use the .min.js file if it exists. I am adding angular the following way:

bundles.Add(new ScriptBundle(Bundles.Scripts).Include(
                        "~/Content/Scripts/angular.js"));

I have angular.js and angular.min.js in the same folder. So according to what I understand the bundler should just use the angular.min.js and do not do anything itself. But when I check the result in the http response, it's different. It's also minified, but all the names are different:

What I get in the browser:

(function(n,t,i){"use strict";function v(n)

Angular.min.js

(function(P,X,u){'use strict';function M(b)

Can someone explain why this is happening? Does the bundler just ignore the .min file or it minifies again .min.js?

P.S. I have tried to delete the angular.js file and I get an empty result after that, so it seems the bundler does not care at all that angular.min.js exist.

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • This does not help, as without bundling turned on I won't even see the bundles but individual files (I have verified it with setting true just in case as well). – Ilya Chernomordik Mar 12 '15 at 09:56

2 Answers2

6

It seems that in case of a ScriptBundle the library does not do what it should and tries to minify any file. I changed it to just Bundle and that seems to make the trick and load the preminified versions.

Found the answer here: Style bundling for MVC4 not using min files

Community
  • 1
  • 1
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • Using Bundle instead of ScriptBundle also helped me to fix some broken javascript errors which seems to be related to bundling process. Minification definitely breaks some JS. Thanks to have shared the trick. – AFract May 26 '16 at 12:11
1

Please have both normal and minified versions of a script in your project under the same folder like

script.js
script.min.js

You add only script.js to a bundle in your code. As a result the script.js included in DEBUG mode and script.min.js in RELEASE mode.

The Microsoft MVC4 Platform Considers that you have at least both minified version & unminified version for each Script or Style Bundle(another files like Debug and vsdoc are available too).

Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
  • This is exactly what I have and it does not work unfortunately. I have Scripts folder with only 2 files: angular.js, angular.min.js and .min.js file is not used in release. – Ilya Chernomordik Mar 12 '15 at 12:13
  • 2
    Some libraries only come with .min files so is there a way to include them? – ChrisP Jul 15 '16 at 00:50
  • @ChrisP I would take into account [this answer](https://stackoverflow.com/questions/11980458/bundler-not-including-min-files/12005272#12005272) for such cases.. – hastrb Oct 02 '17 at 09:57