Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:27:37+00:00 2026-05-29T22:27:37+00:00

I need to dynamically load several JavaScript file assets in a very specific order

  • 0

I need to dynamically load several JavaScript file assets in a very specific order after a page has loaded. I’m trying to use onload, but this seems to fire before the asset has fully loaded. How should I adjust the below script to fire a proper callback to load the next script?

Note: Only needs to work in the latest Chrome, Firefox, Safari, and IE9.

function loadAssets() {
    // Setup script
    var scriptJS = document.createElement('script');
    scriptJS.type = 'text/javascript';
    scriptJS.src = objectUrl;

    scriptJS.onload = loadAssetsNext();

    // Begin insertion
    var headerJS = document.getElementsByTagName('HEAD');
    headerJS[0].appendChild(scriptJS);
},
function loadAssetsNext() {
    // Increment object counter
    objectsCount++;
    
    // Test to see if you should call another item
    if ((objectsCount) < objects.length) {
        // Setup script
        var scriptJS = document.createElement('script');
        scriptJS.type = 'text/javascript';
        scriptJS.src = nextObjectUrl;
        
        // Declare callback to fire after script has fully loaded
        scriptJS.onload = loadAssetsNext();
    
        // Begin insertion
        var headerJS = document.getElementsByTagName('HEAD');
        headerJS[0].appendChild(scriptJS);
    }
}

What I need is something like scriptJS.fullyLoaded = doStuff. Have no clue where to go from here though.

PS: jQuery is not an option or another library. You should be able to do this by slightly modifying the above script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:27:38+00:00Added an answer on May 29, 2026 at 10:27 pm

    The reason your onload event is firing immediately is that you are calling it, not assigning it.

    scriptJS.onload = loadAssetsNext();
    

    This just assigns the returned value from the call to loadAssetsNext to the property onload of the scriptJS object. What you are intending to do is:

    scriptJS.onload = loadAssetsNext;
    

    That sets the onload handler to be the loadAssests function. This should take care of your issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the Zepto equivalent of jQuery.getScript()? I need to dynamically load a JavaScript file
I am trying to dynamically load a KML file into a map depending on
I need to dynamically load a CSS stylesheet into a page that's on a
im new to obj-c, and need help im trying to dynamically load data (10
I need to dynamically load jQuery and jQuery UI from a javascript, then check
Question Updated for Bounty In Flash I need to load a dynamically generated XML
I need to dynamically build a list of textboxes using javascript and jquery. The
Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and
For an application I am writing, I have the need to dynamically load content
I have instances where I need to dynamically load 5-10 literals with the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.