Pro/cons of including .js file before/after BODY tag

Discussion in 'JavaScript' started by hulkster, Jun 1, 2006.

  1. #1
    Easy question that I'm sure there is a definitive answer for - I just can't seem to find it. I am referencing an external javascript file via this pretty standard line:

    <script type="text/javascript" src="/javascript/filename.js"></script>

    So is there *ANY* difference if I have that line in the header area of the HTML (i.e. between the <HEAD> and </HEAD> tags) ... or should it be after the <BODY> tag?
     
    hulkster, Jun 1, 2006 IP
  2. ronmojohny

    ronmojohny Well-Known Member

    Messages:
    729
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    133
    #2
    I think it should be at the end of the file, because the search engines tend to rate the first part of your html code higher than the last part.
     
    ronmojohny, Jun 1, 2006 IP
  3. worud

    worud Guest

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hey hacker ron edwards! where are all your sites now in your sig? watch this guy, he will put links in your website that are hard to find... i have proof
     
    worud, Jun 2, 2006 IP
  4. worud

    worud Guest

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    just ask tech86 what ronmojohny did. he will know...by the way tech86 can help if you have security issues.
     
    worud, Jun 3, 2006 IP
  5. ronmojohny

    ronmojohny Well-Known Member

    Messages:
    729
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    133
    #5
    I think you have a mental illness.. I did not hack anyone's site.
     
    ronmojohny, Jul 23, 2006 IP
  6. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #6
    as long as the script occurs before any functions are called in the page, you should be fine

    although, it may be web standards that it be placed in the head
     
    frankcow, Jul 23, 2006 IP
  7. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #7
    It used to be a "best practice" to put the js includes in the head, along with your meta and css includes, but i believe it is ok cross-browser to put the js include anywhere in the body now...
     
    ccoonen, Jul 24, 2006 IP