|
Post by Sandi Moses on Dec 27, 2007 20:32:39 GMT -5
It seems that lots of programs, StatCounter and Kontera ContentLinkā¢ for example, tell you to place their code just before the </body> tag.
Just as everybody can't be first in a Google search, everybody can't be placed next to the </body> tag.
Is there some sort of protocol to determine who really gets to nestle up to the </body> tag? Or does it make any difference as long as all of them are placed after everything else and before the </body> tag?
Enquiring minds want to know . . . .
Sandi
|
|
|
Post by troyzone on Dec 28, 2007 19:26:22 GMT -5
Hi Sandi,
I don't think it really matters too much where most of these Javascript codes go in your page's source code. Most of them have a single block of code to insert into your site and there is no nesting to worry about like there is with regular HTML opening/closing tags that have two parts working together. Some Javascript like the bookmark code can have part of it placed inside the <head> section, but that's not the same thing as opening/closing tags that have to be nested in a certain order to work properly.
In the case of Javascript code placed inside the <head> section, a script is being defined in the <head> and then wherever you want to use it, you put a piece of code someplace inside the <body> section saying you want to implement that code "here", as in the case of the bookmark code...you can have just one or even a hundred bookmark buttons on your page if you like, all calling the same single script defined inside the <head> section.
I think the main reason that most of those stat counter sites and so forth advise placing their code at the bottom is so that they load last, after the content of your page loads. A browser will parse or "read" your page's code from top to bottom, and you want your page to be visible to your visitors as quickly as possible.
If you place a lot of stat tracking scripts and other such non-visible code near the top of your page, their browser has to parse and interpret all that stuff first before getting to the visible portion of your code, and if you have a lot of such code near the top of your site then some visitors might not wait for the page to appear and click away to another site.
Also, some of those scripts for counters and so forth place little ads or graphics advertising the site providing the script and/or provide a counter number to display on your site...you generally wouldn't want such items appearing at the top of your page, so you would place them at the bottom near the closing </body> tag.
Unless the code provider says otherwise, the location and order in which such blocks of Javascript code are placed really comes down to personal preference, but the general recommendation is to have them at or near the bottom of your page.
I'm not a professional web programmer or anything like that, but this is my take on the subject. Hope this helps.
Troy
|
|