0

I have an issue with the mvc4 bundler not including a file with extension .min.js. In my Scripts folder i have two files: bootstrap.js, bootstrap.min.js

In my BundleConfig class, I declare

#if !DEBUG
            BundleTable.EnableOptimizations = true;            
#endif
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap.js"));

When running in Debug it renders as expected:

<script src="/Scripts/bootstrap.js"></script>

When running in Release it renders as:

<script src="/bundles/bootstrap?v=57XuMf8ytOYgVErEDhgFDRtQ5jlC48bryka4m2DVq_M1"></script>

Why doesn't it render as:

<script src="/Scripts/bootstrap.min.js"></script>
Martictory
  • 17
  • 1
  • Duplicate of [Bundler not including .min files](http://stackoverflow.com/questions/11980458/bundler-not-including-min-files) – Chris Pratt Jun 11 '13 at 17:15
  • When creating a new question, StackOverflow suggests existing questions that may provide the answer. Please pay attention to these and only post a new question if you still cannot find the answer. Google is also a very useful tool for this as StackOverflow questions rank *very* well in Google. – Chris Pratt Jun 11 '13 at 17:16

2 Answers2

3

Why doesn't it render as: <script src="/Scripts/bootstrap.min.js"></script>

Because that's how bundling works in ASP.NET MVC 4. Don't worry, the contents of this /bundles/bootstrap?v=57XuMf8ytOYgVErEDhgFDRtQ5jlC48bryka4m2DVq_M1 is exactly the contents of the /Scripts/bootstrap.min.js. In this case the bundling mechanism hasn't minified the /Scripts/bootstrap.js file but used the already minified version.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • The rendered code actually differs from the bootstrap.min.js file and the rendering takes 230ms. The min.js file starts with: !function(a){a(function(){"use strict" The rendered file starts with: !function(n){n(function(){n.support.transition – Martictory Jun 11 '13 at 07:37
0

The reason you want to use bundles.

  • Declare one statement but generates multiple import resources codes.
  • Minify your js or css code
  • Bundle mutiple files into one file which will reduce the browser request number.
  • Bundle will give the request url a suffix which is generated based on the files. So if you don't cache the page, there will be no js/css cache problem, you don't need to clear browser cache.

By default, when you're in debug mode (you can modify your Web.config to set if enable DEBUG), the js/css files will not be bundled, so you can see the files seperately which will make it easier to debug.

When it's not debug enabled, the files will be bundled.

So if you already have .min.js files, you can import them directly in your page.

Jason Li
  • 1,528
  • 1
  • 12
  • 20