SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving JS after CSS to speed up the website

    I read somewhere that putting Javascript code after CSS code on webpages makes them feel like they load faster. I was wondering if any of you has any experience with this and if you do follow this rule in your projects.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Yep i have heard of this and its 100% true, before when i had CSS and javascript set out of order the page loaded kind of slow but as soon as i arranged the CSS and javascript the page loaded faster.

    In my personal experience i would say do this all the time as it does work.

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,203
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    The recommendation these days is to put all of your JavaScript just before the closing </body> tag. That way the rest of the page has loaded before JS operates on it.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ralph.m View Post
    The recommendation these days is to put all of your JavaScript just before the closing </body> tag. That way the rest of the page has loaded before JS operates on it.
    As confirmation, here are the Best Practices for Speeding Up Your Web Site among which is: Put Scripts at the Bottom
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    In addition placing all JavaScript at the bottom promotes good practice – avoiding embedded and inline scripting.
    The only code I hate more than my own is everyone else's.

  6. #6
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm moving all my js files just before </body> and it really gives me the impression that pages load faster. I'll start doing this always from now on.


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
  •