Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesnt the MVC4 bundling bundle Knockout.js?

I have downloaded MVC4 and trying to work out how the bundling feature works in a standard project. It would seem that having the bundle:

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>

Brings back all the jquery.js files but not the knockout.js files in the included scripts. Why is this? And also what is the _references.js file about and why is the knockout.js file commented out?

like image 925
Exitos Avatar asked May 14 '12 08:05

Exitos


1 Answers

If you look into your project Global.asax file, you should find there something like this:

protected void Application_Start()
{
    ...
    BundleTable.Bundles.RegisterTemplateBundles();
}

Now the RegisterTemplateBundles is registering only a predefined subset of scripts:

  • jquery-*
  • jquery.mobile*
  • jquery-ui*
  • jquery.unobtrusive*
  • jquery.validate*
  • MicrosoftAjax.js
  • MicrosoftMvc.js
  • modernizr*
  • AjaxLogin.js

If you want some additional files you could either change RegisterTemplateBundles to EnableDefaultBundles:

protected void Application_Start()
{
    ...
    BundleTable.Bundles.EnableDefaultBundles();
}

Or create your own custom bundle (you can read more about bundling and minification here). You should also know that EnableDefaultBundles has some performance impact.

The _references.js file is used by Visual Studio for JavaScript intellisense. You can learn more from following article:

  • JavaScript Intellisense in VS11, The _references.js File
like image 186
tpeczek Avatar answered Sep 17 '22 06:09

tpeczek