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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:39+00:00 2026-06-08T21:13:39+00:00

I have started building a web site and have used Require.js for selectively loading

  • 0

I have started building a web site and have used Require.js for selectively loading scripts which I require to implement functionality. What I am experiencing is:

  • the “main” script has not finished executing (or even downloading) before some of my code uses “require” to load dependencies. What this means is that the require.js config has not run and does not know the locations of my scripts.
  • because the require.js config has not run by the time my code needs to use it, the “shim” mechanism has not been initialised and cannot be used.

The Common Errors page along with a lot of the issues I seem to be reading about online while trying to solve my own problems seem to suggest that this is not the right tool for the job.

This seems to be useful for single page applications or node.js applications, but not traditional sites where other scripts could be running before require.js has been initialised.

If require.js is not the right tool for the job, is there a right tool for this job? If so then what is?

  • 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-08T21:13:40+00:00Added an answer on June 8, 2026 at 9:13 pm

    Are you loading the require.js script asynchronously (with an async='async')? You want requirejs to load synchronously. Once it’s loaded, it will load further scripts, like your main.js file, asynchronously. They may all load out of order, but the code will actually get executed in the right order (respecting the declared dependencies).

    So in your page template, you would have this:

    <script src="/Scripts/require.js" type="text/javascript" data-main="main.js"></script>
    

    That will load RequireJS, and once it’s loaded it starts loading your main.js asynchronously. Typically main.js does not define any modules, it just makes use of modules defined in other files. These dependencies are listed in the require() call:

    require(["moduleA", "moduleB"], function(A, B){
      // Do something with A and B
      A.someFunction();
      B.someOtherFunction();
    });
    

    The files moduleA.js and moduleB.js must wrap their contents inside a define(). In moduleA.js (which depends on module C):

    define(["moduleC"], function () {
      // Build up an A
      var A = ....;
    
      return A;
    });
    

    I wonder now if you’re wrapping your modules in a define call. Not doing that could explain the out-of-order execution you’re experiencing.

    RequireJS is a perfectly valid tool on a traditional site, not just on a single-page site.

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

Sidebar

Related Questions

I'm just getting into using REST and have started building my first app following
I am building an app to learn Django and have started with a Contact
I have recently started programming in PHP. I am building a cart in PHP.
I'm writing a web app which is used a SaS. Each customer has their
We have just started our new assignment - web-based project. Before I get directly
I recently started building a console version of a web application. I copied my
I have recently started building an application in rails (3.0.5). Just to get things
I'm just getting started learning how to use Subversion for building my web applications,
I'm looking to start building web apps. I need basic CRUD functionality. I understand
I have a question regarding Date and Time for MYSQL. Basically I started building

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.