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 6762947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:25:08+00:00 2026-05-26T14:25:08+00:00

I am using xmlhttprequest (and eval ) to dynamically load scripts. Next I evaluate

  • 0

I am using xmlhttprequest (and eval) to dynamically load scripts. Next I evaluate the script and look to see if there are any other scripts to load. Along the way if any of the scripts cause and exception, the error message reported indicates the line number associated with eval, not with the actual error in the script.

On another question it was suggested I use <script> instead to get better error messages. Unfortunately, <script> is asynchronous, and I won’t be able to control the order of loading of scripts (I need an onload callback).

How do I implement synchronous behaviour in <script> commands


Some more info as to what I aim to achieve

Every script has a list of other scripts it loads, stored in a list, lets call it _toLoad

Lets say we have a script ‘Main.js’ with a load list like so

_toLoad = [['A.js'] , ['B.js'] , ['C.js'] , ['D.js' , 'E.js' , 'F.js']]

Which states that once loaded, the file ‘A.js’ must be loaded next. Once ‘A.js’ is loaded, ‘B.js’ must be loaded next. Once ‘B.js’ is loaded, ‘C.js’ must be loaded next. Once ‘C.js’ is loaded, ‘D.js’ ,’E.js’ , and ‘F.js’ must be loaded, in any order.

I could use <script> to load ‘Main.js’, evaluate it’s _toLoad list and start loading the other scripts, in the correct order. But what happens if ‘A.js’ has several scripts it also loads? I want those to load in the background, and not to delay ‘B.js’ from loading

What if ‘A.js’ has a load list like so:

_toLoad = [['A2.js'] , ['B2.js'] , ['C2.js'] , ['D2.js' , 'E2.js' , 'F2.js']]

Is I would have to go through and issue <script> statements for those. It seems like a depth first approach, when I want a form of breadth first.

  • 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-26T14:25:08+00:00Added an answer on May 26, 2026 at 2:25 pm

    One of the linked questions mentioned setting the innerHTML of the script tag element. I think this might do the trick

    function load(toEval, callback){
        __global_callback = callback;
    
        var node = document.createElement('script');
        node.innerHTML = toEval + '; __global_callback()';
        document.getElementsByTagName('head')[0].appendChild(node);
    }
    
    load("console.log('before...');", function(){
        console.log('...and after');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I am trying to do only using XMLHttpRequest, is this: The script downloads
I have an XML object (loaded using XMLHTTPRequest 's responseXML ). I have modified
I am trying to make asynchronous calls using xmlhttprequest object so it completely works
I am using an XMLHttpRequest to POST a JSON string to PHP. The JSON
I'm doing some straight up asynchronous calls from javascript using the XMLHTTPRequest object. On
Is it possible to do a HTTP Head request solely using an XMLHTTPRequest in
I am trying to implement a simple request to Wikipedia's API using AJAX (XMLHttpRequest).
I have a web application that adds contextual information to XmlHttpRequest objects using the
Using ASP.NET MVC there are situations (such as form submission) that may require a
I'm using XMLHttpRequest, and I want to access a local variable in the success

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.