I you have a view that is using the _Layout.cshtml and you tell the view to Reference script libraries, is that redundant since you will be referencing the script libraries from the _Layout.cshtml or am I missing something here. In all of the MVC tutorials I have gone through from Microsoft, they always leave Reference Script Libraries checked.
When you check "Reference Script Libraries" this just adds references to jquery.validate.min.js
and jquery.validate.unobtrusive.min.js
you would only need these javascript libraries on pages with forms as it validates what a user has entered.
You generally wouldn't reference these in the _Layout.cshtml
as they are not needed on non-form pages and would be unnecessary HTTP request performed when loading the page.
If however you do have a form on every page or most pages and think it is acceptable to make the HTTP request on pages without forms then you can reference them in the _Layout.cshtml
and simply not check the "Reference Script Libraries" when creating views.
Yes, it is - referencing same script two times in both layout and view would result in script run two times in browser. Even if that was not error-prone, you actually would not want to waste browser resources in processing same script twice. Basically, those MVC tutotials are there to give you the basic knowledge and skills, not the production-ready code. In asp.net-mvc, you could use the great Cassette library, which does much more than helping script and stylesheet reference management - including minification, caching, compressing, combininig, etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With