SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS in the head ... or body ... why not?

    Hi all,

    I've got a script I want to start using on my site, it's the son of suckerfish menu system. There is a bit of JS required, and altho it doesn't specify that it go in the "head" section I assume it must as most do ...

    But my deal is this - I have a common menu include for the 100+ pages - I stuck the JS at the top of the include (include contains only html - no head tags) and the script works fine. This saves me having to insert the JS into all of those files. Yes, I'm a bit lazy at times.

    My question is this: Why is most JS inserted between the head tags? I see that it will work in the body tag - so what is the advantage of the head tag placement? Should I bite the bullet and do the insertions - or will it be okay as is?

    Thanks!
    Dodge

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The head part of the page is loaded first, so any JS that should be used later in the body is included there. Likewise, even the JS in body part is completely valid as long as it included before used.

    If it works for you, means you did everything ok.
    Saul

  3. #3
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thanks so much

    Dodge


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •