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> 
2
  • Duplicate of Bundler not including .min files Commented Jun 11, 2013 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. Commented Jun 11, 2013 at 17:16

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.