SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 54 of 54
  1. #51
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    I still disagree that "in the head" is where it belongs.

    I do agree that having a script element randomly placed in the body is a pain to find and maintain, and it shouldn't be there. However, I think right before the closing body tag is perfectly acceptable and just as easy to maintain as if it's in the head. And you get a boost in load speed.

    Once again, the exception to this is in cases like Stormrider describes where you use JS to heavily change the layout. In these cases I'd put it in the head so you don't get a random rearrange of the screen.

    However, things like click events and other things that don't appear initially should be in the footer.

  2. #52
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    I may be missing something, though;
    IE6 and IE7 get blocked simply loading javascript... IE8 does not.

  3. #53
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samanime View Post
    I still disagree that "in the head" is where it belongs.

    I do agree that having a script element randomly placed in the body is a pain to find and maintain, and it shouldn't be there. However, I think right before the closing body tag is perfectly acceptable and just as easy to maintain as if it's in the head. And you get a boost in load speed.

    Once again, the exception to this is in cases like Stormrider describes where you use JS to heavily change the layout. In these cases I'd put it in the head so you don't get a random rearrange of the screen.

    However, things like click events and other things that don't appear initially should be in the footer.
    But then it always worries me... what if someone tries to click before the script has loaded? Or interact with any element that the script will attach events to.

  4. #54
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    I do worry about that as well and weigh the pros and cons:
    - Is this something that is likely to load substantially before the script?
    - Is this something that will look broken before the script loads?
    - etc

    If it is something I worry about, I will move it above. However, a lot of times they're things that don't matter if they're loaded or not by the time they click them (or they'll load before they're able to click them). Most click actions have actions that work without the Javascript as well, just not as perfectly.


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
  •