I have an Asp.net MVC project that modestly uses jQuery scripts. My views also display partial views in them, or are returned using the RenderPartial or RenderAction helper methods. Partial views are commonly used to encapsulate some common display, but they may also have some client-side script functions. My javascripts have the same names as the views they are associated with.
So, if I have a partial view of UserInformation.ascx , I have the corresponding UserInformation.js file. Most of these script files register functionality for the DOM ready event, so they will not be executed immediately.
The problem is that these scripts are added to the parent views. Therefore, if a particular view uses my partial view, it also needs to add the appropriate script file. Therefore, if someone forgets to add a script to the main view, my partial view function will not work.
As for browser execution and speed (or any other problems), is it better to include all the scripts in the XHTML header element, or does it not matter if I referenced these scripts inside my partial views? So I could avoid human error by forgetting to add a script to the view? However, I may encounter the problem of linking to the same script file. Especially if the same partial part is used several times in the same representation.
Are there any differences when we refer to scripts inside HEAD or BODY elements?
Are there any doctype related issues (I use XHTML Transitional)?
What is the most common pattern?
It would be nice to have some kind of script registration function in Asp.net MVC that would prevent me from loading the same script file several times ...
source share