1

I have a simple situation:

<script src="1.js"></script>
<script src="2.js"></script>

I want 1.js to load another javascript 3.js in and execute it before 2.js. I can not change the html, I can only change the 1.js code。

I tried to make a synchronize ajax call in 1.js, but still 3.js is loaded after 2.js.

Any other solution ?

0

3 Answers 3

2

Append the contents of 3.js to 1.js. If you would rather keep them separate in your code base, you can combine them in your build step. Having one less JavaScript file for the browser to load will have the pleasant side effect of reducing page load times.

Sign up to request clarification or add additional context in comments.

6 Comments

The OP may not have any control over or access to the content of 3.js.
@RobG: My only assumption is that 3.js is readable at build time. If this is not the case for some bizarre reason then I suppose my solution wouldn't be possible. Let's wait to see if the OP clarifies this point.
I had to load it separately, I need to send some parameters to 3.js and 3.js is dynamically created.
@virsir: Do you have control over the code that dynamically creates 3.js?
I do, but I can not change the html, that means I can not bring the parameters in.
|
0

Use document.write in 1.js to add 3.js. It should be added immediately afer 1.js, but no guarantees.

Comments

0

Try this:

http://www.andresvidal.com/jsl

It has lots of way to load different scripts at different times.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.