Why is MVC4 not included with Knockout.js?

I downloaded MVC4 and tried to figure out how the binding function works in a standard project. It would seem that having a bunch:

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

Returns all jquery.js files, but not knockout.js files in the attached scripts. Why is this? And also what is the _references.js file and why is the knockout.js file commented out?

+6
source share
3 answers

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

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

RegisterTemplateBundles now only registers a predefined subset of scripts:

  • JQuery - *
  • jquery.mobile *
  • Jquery-uh *
  • jquery.unobtrusive *
  • jquery.validate *
  • MicrosoftAjax.js
  • MicrosoftMvc.js
  • Modernizr *
  • AjaxLogin.js

If you need additional files, you can either change RegisterTemplateBundles to EnableDefaultBundles :

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

Or create your own package (you can learn more about the bundle and mini-configuration here ). You should also be aware that EnableDefaultBundles affects performance.

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

+8
source

tpeczek is true. Most people do not use Knockout.js, so it does not turn on by default. Bundling / Minification (BM) has changed significantly for RC, and it will be much easier to add files to packages. See My Tutorial on Combining and Minimizing

+2
source

I managed to add the file to the package with the following line of code added after RegisterTemplateBundles ()

 BundleTable.Bundles.RegisterTemplateBundles(); BundleTable.Bundles.Where(x => x.Path == "~/Scripts/js").First().AddFile("~/scripts/knockout-2.0.0.js"); 
0
source

Source: https://habr.com/ru/post/915648/


All Articles