Milktea
Milktea

Reputation: 161

Using javascript in MVC3, in master or child page

I'm building a web application using MVC3 and I'm wondering what the etiquette is in regards to having javascript (whether it's embedded or external) in the master page, and then having javascript that pertains to an individual child page.

For example, is it fine to have an embedded section for javascript in the maser page, and then another one in the child page, such that there will be two sets of tags when the page is rendered in the browser?

What is the generally accepted way to do this? Thank you.

Upvotes: 1

Views: 122

Answers (2)

Cory Danielson
Cory Danielson

Reputation: 14501

That is acceptable. There's no problem.

The alternative way to execute javascript code that runs on only 1 page would be to add javascript code within your master .js file, and, on each page load, check

if (this.href == "http://.............") 
{ 
    /* execute unique js */ 
}

Upvotes: 2

Related Questions