ASP.NET MVC Loading scripts in partial views
<p>My entire website is an Ajax website, so all of my views (apart from Layout) can either be loaded normally or via an ajax actionlink.
If I put the Javascipt files in with the partial views then all of the code works as expected, but the scripts get loaded multiple times (thus making the user download more scripts, all of them aren't being cached for some reason either).</p>

<p>If I put the script files in my Layout, then they only get loaded once but if a partial view gets loaded then the JS code for that partial view doesn't work obviously, because the scripts were already loaded when the partial view wasn't rendered.</p>

<p>My question is, how can I make the scripts get loaded only once, but also somehow have them affect partial views?</p>

<p>Index view:</p>

<pre><code>&lt;script src="/Scripts/Build/module.min.js"&gt;&lt;/script&gt;
&lt;script src="/Scripts/Build/upload-index.min.js"&gt;&lt;/script&gt;
</code></pre>

<p>Layout:</p>

<pre><code>&lt;li&gt;
    @Ajax.ActionLink("Upload", "Index", "Upload", new {Area = "Music"}, new AjaxOptions {HttpMethod = "GET", UpdateTargetId = "body-wrapper", InsertionMode = InsertionMode.Replace, OnSuccess = "updateHistory", AllowCache = true }, new {@class = "nav-link"})
&lt;/li&gt;
</code></pre>

<p>You can see the scripts getting loaded multiple times if they are in the partial view:
<a href="https://i.stack.imgur.com/hTMe2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hTMe2.png" alt="enter image description here"></a></p>