SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Anything better than document.ready?

    I have some JQuery superfish menu's and they do not load until my site document is fully loaded (which includes images). It seems Google Analytics at the bottom adds about 5 secs or more loading time.

    I suppose window.onload is even slower, has anyone ever had a problem like this wanting their JS to load faster?

    I guess the good part is that the superfish menu's load their CSS based look first.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Put the JavaScript just before the </body> tag and it will run after the HTML has loaded without waiting for any of the other files to finish loading. JavaScript does single thread for downloads called from HTML so it will wait for any other files already being downloaded.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using a typical "document ready" function (such as jQuery's) won't wait for the images or scripts to load (Unless it's a very old browser, in which case most docReady functions will fallback to window.onload) so it should be quite fast. The only way to speed it up (slightly) would be to follow Felgall's advice.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •