Fast loading of Javascript

Discussion in 'JavaScript' started by swaraj_here, Nov 1, 2007.

  1. #1
    Dear All,

    I am using a Java script for left sub-menus in the navigation. But it is taking too much time to load in online browser. Can any one of you please tell me how to load the script faster so that the navigation menu can be seen right in the moment of page loading.

    Please help me. Initially I linked that script in an external script, but now I have put embedded that in the page header. Still it is not working.

    I need a solution.
     
    swaraj_here, Nov 1, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you first have to ascertain whether the issue is in the download speed or code execution or both.

    if it takes too long for the browser to execute the code, then you'd need to have a look at the code and try to optimize it.

    if the download is slow, there are many ways to look at to improve it. i'll list some after you've confirmed that this is the issue you're having, if you're interested.

    regarding having the script as a separate file vs embedded in the html header, it's generally more speed efficient if you keep the it as a separate file. because that way, the javascript file can be cached by the browser.
     
    phper, Nov 1, 2007 IP
  3. fablex

    fablex Peon

    Messages:
    468
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If its in loading time, just strip all the comments from it, and put the code all behind eachother on one row (check if it works afterwards of course!). I decreased some .js file sizes by 60% doing this.
     
    fablex, Nov 7, 2007 IP
  4. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #4
    do all ways above is good
     
    temp2, Nov 7, 2007 IP