Reputation: 4152
In my ASP.NET page, I am referring to an external JavaScript file.
As per my learning in the web, it's recommended always to put inline JavaScript code at the bottom of the page. There is no information about how to do it for an external JavaScript reference.
I want to know, if I am referring to an external JavaScript file, where should I write it?
> 1. Inside <Head/> top of the page
> 2. bottom after closing tag of </form>
Upvotes: 2
Views: 1369
Reputation: 65887
Putting JavaScript code at the bottom of the page is effective only if that's an inline script.
Checkout the Google page-speed tutorial for more information.
Recommendations
Put external scripts after external stylesheets if possible.
Browsers execute stylesheets and scripts in the order in which they appear in the document. If the JavaScript code has no dependencies on the CSS files, you can move the CSS files before the JavaScript files. If the JavaScript code does depend on the CSS contained in an external file — for example, styles that are needed for output you are writing to the document in the JavaScript code — this isn't possible.
Put inline scripts after other resources if possible.
Putting inline scripts after all other resources prevents blocking of other downloads, and it also enables progressive rendering. However, if those "other resources" are external JavaScript files on which the inline scripts depend, this might not be possible. In this case, it's best to move the inline scripts before the CSS files.
Upvotes: 1
Reputation: 172
If you're going to use that script dynamically for each page, there is better way to do it. Put this into your masterPage,
protected void Page_Load(object sender, EventArgs e)
{
string a = "$(function() {";
a +="$('.Utility.division() .items').hide();";
a += "});";
a += "</script>";
Page.RegisterClientScriptBlock("a", a);
}
Utility.division()
is your dynamic variable which is declared in utility.cs//
.
Upvotes: 1
Reputation: 463
@spielersun: I think you mean Utility.division()
is your dynamic variable which is declared in utility.js
rather than utility.cs
.
Upvotes: 0