www.webdeveloper.com
Results 1 to 4 of 4

Thread: Load Scripts in Specific Order or delay

  1. #1
    Join Date
    Feb 2006
    Posts
    50

    Load Scripts in Specific Order or delay

    I have 4-5 scripts running on one page at any given time. I have them in the order I want them to load but it seems the scripts I have starting first are lagging while the rest of the other scripts load so in turn the script loaded first seems to finish loading last.

    ex
    jquery
    flash detect
    js menu
    dom analytic

    but even in that order jquery finishes loading last. How can i set a delay to the rest of the scripts without modding them? some of them are within the page but others are external absolute paths to other scripts.

    Can this be done?

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    I have a few projects that write new arrays. When the page closes, I wish to write a new .js file and save it (local application) So now, I have some options to load different .js scripts from form buttons. I'm very sure you could use this script to call each one and after load, load the next. If it doesn't happen to your satisfaction, could use a setTimeout function....
    PHP Code:
    function loadJS(url){    url=bckslash(url);    var ul=url.substring(url.lastIndexOf('.')+1,url.length); ul=ul.toUpperCase();    document.getElementById('sounds').style.visibility='visible';
       if( 
    ul=='JS'){
          var 
    document.createElement("script");
          
    e.src url;
          
    e.type="text/javascript";
          
    document.getElementsByTagName("head")[0].appendChild(e);      
        
    document.getElementById('jsLoaded').innerHTML=url.substring(url.lastIndexOf('\\')+1,url.length);document.getElementById('jsLoaded').title=url;
        
    grabFolder(path)
       }
     else{for(
    i=0;i<showImgExt.length;i++){if(ul==showImgExt[i]){grabFolder(    url.substring(0,url.lastIndexOf('\\')),url.substring(0,url.lastIndexOf('\\'))    );}}
     }


    sorry, there's probly lines there you don't need. The bckslash function replaces forward slashes in the path. If your scripts are in the same directory, no need for that.

  3. #3
    Join Date
    Feb 2006
    Posts
    50
    do the backslashes represent the path to the js file?

  4. #4
    Join Date
    Oct 2006
    Posts
    939
    In my application, I was using a file input form button to browse. The slashes are forward or backward, its a mess. I only ripped the code out of an existing file. You can see it's only handling .js files,, here this might be better

    PHP Code:
    function loadJS(url){    
          var 
    document.createElement("script");
          
    e.src url;
          
    e.type="text/javascript";
          
    document.getElementsByTagName("head")[0].appendChild(e);      
        

    Now, just use a group of buttons to load your scripts. Still, it looks like this only works on .js don't worry about slash, just use the full path in the argument of the function

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles