admin管理员组

文章数量:1428611

I currently am working on a large site with many different issues to contend with. One being that I have no easy way to include a script into my <head> without manually doing it for 500+ pages.

I have the possibility to include jQuery.min just inside the <body> tag from an include located there.

My question is, aside it not being a standard implementation, would there be any negative effects from not loading jQuery within the <head> tag? Will all the functions be available?

I am aware that if I do this, I will not be able to call jQuery from within the <head> or before this include... that's okay.

example:

<head>
Standard Head Stuff
</head>
<body>

<div>Some Content</div>

<!-- My Include is roughly here -->
<script type="text/javascript" src="jquery.min.js"></script>

<div>More content</div>

<script type="text/javascript">
 $(document).ready(function(){
// Put my jQuery mands here
});
</script>

</body>

I currently am working on a large site with many different issues to contend with. One being that I have no easy way to include a script into my <head> without manually doing it for 500+ pages.

I have the possibility to include jQuery.min just inside the <body> tag from an include located there.

My question is, aside it not being a standard implementation, would there be any negative effects from not loading jQuery within the <head> tag? Will all the functions be available?

I am aware that if I do this, I will not be able to call jQuery from within the <head> or before this include... that's okay.

example:

<head>
Standard Head Stuff
</head>
<body>

<div>Some Content</div>

<!-- My Include is roughly here -->
<script type="text/javascript" src="jquery.min.js"></script>

<div>More content</div>

<script type="text/javascript">
 $(document).ready(function(){
// Put my jQuery mands here
});
</script>

</body>
Share Improve this question edited Jan 20, 2011 at 1:41 thirtydot 228k50 gold badges392 silver badges354 bronze badges asked Jan 20, 2011 at 1:32 dpmguisedpmguise 7281 gold badge4 silver badges10 bronze badges 2
  • I would just run a find/replace on all the "500+" pages to add an include file inside the <head>, and add jQuery to that include file. It's probably worth the hassle in the long run. – thirtydot Commented Jan 20, 2011 at 1:45
  • True, it would be desired. Unfortunately I only have a web interface with check in/out to interact with which eliminates the possibility of doing this. – dpmguise Commented Jan 20, 2011 at 1:57
Add a ment  | 

2 Answers 2

Reset to default 5

The only issue is that a page is loaded from top to bottom and so if you were to place the include statement into the header than you would be assured that the library would be loaded immediately. Otherwise the library may only be loaded at a later time which can cause a delay in some effects potentially.

Head or body, inline code will execute when phrased. Code is generally placed in the head so external libraries can be loaded before the page is (so effects can be run on dom ready). Code in the body will be run once the dom is done with the header code, and done loading page elements (once in the body, elements are loaded from top to bottom). So any code in the body will be executed once the page had loaded (up to that point)

本文标签: javascriptAre there negative effects from not loading jQuery in the ltheadgt tagStack Overflow