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

  • SEARCH
  • Home
  • 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 7935987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:04:43+00:00 2026-06-03T22:04:43+00:00

I have the following code using require.js. utilities.js: define([thirdparty-script-A.js], function(){ … }); application.js: define([utilities,

  • 0

I have the following code using require.js.

utilities.js:

define(["thirdparty-script-A.js"], function(){ ... });

application.js:

define(["utilities", "order!thirdparty-script-A.js", "order!thirdparty-script-B.js"], function(){ ... });

thirdparty-script-B.js has a dependency on thirdparty-script-A.js and will not load properly if thirdparty-script-A.js has not finished loading (executing).

To summarize, the dependency structure looks something like this:

  utilities +---> thirdparty-script-A.js <---+ thirdparty-script-B.js

        ^                   ^                          ^
        |                   |                          |
        |                   +                          |
        |                                              |
        +------------+ application.js +----------------+

Looking at firebug, I see that the fetch order is:

  1. utilities
  2. thirdparty-script-A.js
  3. application
  4. thirdparty-script-B.js

And from debugging with console.log() (and from a theoretical standpoint), the load (execution) order is:

  1. thirdparty-script-A.js
  2. utilities
  3. thirdparty-script-B.js
  4. application

Now here’s the problem.
For the most part, the above works just fine in firefox, chrome, and IE9. However, there is a case where thirdparty-script-B.js fails to load because thirdparty-script-A.js hasn’t finished loading yet. In fact console.logs showed that thirdparty-script-B.js executed FIRST, then third-party-A.js, utilities, and finally application. What is going on? So far, I can only reproduce this problem in IE9.

It is very odd because in application.js, I use the order plugin to guarantee the order in which the two third party scripts load. And yet the scripts execute out of order.

Upon further investigation, I noticed that the problem occurs only when thirdparty-script-A.js takes longer to fetch than thirdparty-script-B.js. Which makes me speculate that the order! plugin doesn’t work with define(). Theoretically, thirdparty-script-B.js should wait on executing even if thirdparty-script-A.js took 20 seconds to fetch and load. That’s how order! behaves, no?

Another theory is that it won’t work if any of the files in order! were required in another module up the chain (thirdparty-script-A.js in utilities.js).

I do have a workaround solution to this. And that is to wrap application.js in a require() and have it load all the traditional scripts first.

require(["order!thirdparty-script-A.js", "order!thirdparty-script-B.js", "application"], function(app){
//app.init
}

For a 60+ script application however, the require list can get long and messy…

Can anyone enlighten my as to why define() and order! behave the way they do?

Thanks a bunch!

And yes, thirdparty-script-A and B are cached. =)

  • 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-06-03T22:04:44+00:00Added an answer on June 3, 2026 at 10:04 pm

    The trick is to wrap everything in modules. I usually do this “repackaging” on third-party plugins that rely on jQuery. That way, you are sure that jQuery is loaded (and $ exists) when the plugin is loaded. In this method, the order plugin is not needed.

    By “repackaging”, you just wrap the plugin code in a define() call, with it’s dependencies, and load it normally.

    in application:

    define(['utilities','scriptA','scriptB'],function(){
        //application code
    });
    

    in utilities:

    define(['scriptA'],function(){
        //utilities code
    });
    

    in scriptB

    define(['scriptA'],function(){
        //scriptB code
    });
    

    in scriptA

    define(function(){
        //scriptA code
    });
    

    So the order is:

    Loading |      Application       A
            |   Utilities, Script B  |
            V       Script A         | Execution
             \----->----->----->----/ 
    

    ScriptA could have been loaded and executed earlier since Application depended on it. But to be safe, you should do it this way. That way, you are sure dependencies are loaded properly.

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

Sidebar

Related Questions

I have the following Javascript code (using jQuery): floatUpAndDown(); function floatUpAndDown() { $(#bird).animate({top: '+=30px'},
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I have the following code: using System; using System.Diagnostics; using System.IO; using PdfSharp.Pdf.Printing; namespace
I have the following code: using (BinaryReader br = new BinaryReader( File.Open(FILE_PATH, FileMode.Open, FileAccess.ReadWrite)))
I have the following code using jQuery Validate. $(#register).validate({ debug: true, errorClass:'error', validClass:'success', errorElement:'span',
I have the following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
In my view I have the following code: @using (Html.BeginForm()) { @Html.TextBox(Date2, Model.Date2) <br/>
I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
I'm using some not optimal code written by me... :-| I have following code:
I have the following code in a partial view (using Spark): <span id=selectCount>0</span> video(s)

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.