Adding a referece of Javascript files in Master Pages is a pain. Because the location of Javascript can be in directory, you can simply write this:
<script type="text/javascript" src="../Scripts/some.js />
This will NOT work as when you deploy your site, it would depend on the directory structure.
Another problem is you also can NOT do the following:
<script type="text/javascript" src='<% = ResolveUrl("~/Scripts/some.js") %>' />
because Master Page won't allow any server-side tags.
The ultimate solution to this I found, is, as follows:
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude("somescript", ResolveUrl("some.js"));
}
which produces the result
<script src="/Test1/some.js" type="text/javascript" />
Perfect! If you have a better solution, please add in the comments section. I'm definitely interested.
Simon drew my attention that my technique above will add the JavaScript file to the < BODY > section of the page. In some cases, you don't want that. Here is my solution to add Javascript file to the < HEAD / > part. Thanks Simon.