Is it better to load ALL my resources in my base layout/template view, or directly in the partial view I load in ajax?
Exemple:
_layout:
[...]
<head>
<script src="file.js"></script>
<link href="file.css"></link >
</head>
[...]
OR
_layout:
[...]
<head>
</head>
[...]
partialView (loaded later in AJAX):
<div>
<script src="file.js"></script>
<link href="file.css"></link >
</div>
What you would normally be doing is pushing some script resources into a list on the viewbag, and then get your template to go through that list and generate the script include for you.
On the partial:
In the layout (_Layout.cshtml)
In normal circumstances this allows you to associate scripts with partial which is quite nice, and is a good idea if you are only refreshing a partial which exists on the page on page load.
The scripts should be preloaded on the page. You shouldn’t be reloading scripts by getting a script resource via ajax and injecting it into the page. Ideally you wouldn’t be getting html over ajax either, but some people find this acceptable. You only want to inject the html into the page and not more scripts. If you have event handlers on the items inside the partial view, consider attaching the event handlers to the container instead of the elements individually.
However, given that you are reloading potentially any view, I think you are better off including your scripts in the head. This will ensure that you don’t find any conflicting scripts later on. Your site is essentially an application that costs the user a small overhead to load initially but does not need to be refreshed.