Martictory
Martictory

Reputation: 17

ASP.Net MVC Bundler not including my .min file in Release

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>

Upvotes: 0

Views: 817

Answers (2)

Jason Li
Jason Li

Reputation: 1585

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.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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.

Upvotes: 3

Related Questions