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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:08:18+00:00 2026-06-11T01:08:18+00:00

I have a requirejs project that has been optimized into a single file, which

  • 0

I have a requirejs project that has been optimized into a single file, which I am loading synchronously. The code loads as expected, but the modules are still loading asynchronous (they aren’t available until later in the loading process) and it’s causing problems for some legacy code I’m hoping it will work with.

Given the code below, is there any way of making main-build‘s methods available immediately after loading, before legacy_code.js is loaded?

<script type="text/javascript" src="/scripts/vendor/require.js"></script>
<script type="text/javascript" src="/scripts/main-build.js"></script>

<!-- At this point, the code is set up and it will be invoked later -->
<!-- ...but the next file requires to access methods in the modules.-->

<script type="text/javascript" src="/script/legacy_code.js"></script>

If worst comes to worst, I can write my own versions of define() and require() (which would also free up a lot of bandwidth since all it would need to do is catalogue and invoke the modules), but I’m hoping there’s a built-in way to do this.

  • 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-11T01:08:19+00:00Added an answer on June 11, 2026 at 1:08 am

    Answering my own question here. After looking around a long while, I can’t see any way to load Requirejs code synchronously or invoke modules immediately after loading. So I ended up writing some code to temporarily overwrite require and declare methods. It works for my use case, but may require changes if anyone else needs it. I’m sure it can be optimized more than it is right now, but it works.

    You can find the code on GitHub, which I will try to maintain.

    The code at this point looks like this:

    (function () {
        var self = {},
            originalDefine = window.define,
            originalRequire = window.require,
            modules = [];
    
        var define = function (id, deps, fn) {
            if (id !== 'requireLib' && id !== 'text') {
                modules.push({"id": id, "deps": deps, "fn": fn});
            }
        };
    
    
    
        var require = function (deps, fn) {
            var sortedModules = [],
                unsortedModules = [],
                resolvedDeps = {},
                maxAttempts = 1000,
                module,
                dep,
                depList,
                canAdd,
                i,
                j;
    
            unsortedModules = ([]).concat(modules);
            while (unsortedModules.length > 0 && --maxAttempts > 0) {
    
                for (i = unsortedModules.length - 1; i >= 0; i--) {
                    canAdd = true;
                    module = unsortedModules[i];
    
                    for (j = 0; j < module.deps.length; j++) {
                        dep = module.deps[j];
                        if (resolvedDeps[dep] === undefined) {
                            canAdd = false;
                            break;
                        }
                    }
                    if (canAdd) {
                        resolvedDeps[module.id] = module;
                        sortedModules.push(unsortedModules.splice(i,1)[0]);
                    }
                }
            }
    
            for (i = 0; i < sortedModules.length; i++) {
                module = sortedModules[i];
                depList = [];
                for (j = 0; j < module.deps.length; j++) {
                    depList.push(resolvedDeps[module.deps[j]]);
                }
                resolvedDeps[module.id] = module.fn.apply(this, depList);
            }
    
            depList = [];
            for (i = 0; i < deps.length; i++) {
                depList.push(resolvedDeps[deps[i]]);
            }
    
            fn.apply(this, depList);
    
            window.define = originalDefine || function () {};
            window.require = originalRequire || function () {};
        };
    
        window.define = define;
        window.require = require;
        window.require.config = function() {};
    
        return self;
    } ());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a project that requires downloading a zipped file off
I have a script that generates a temporary HTML file that has links to
I'm working on a project that has a proprietary file format. The project has
I have been working on a project that requires a bar graph to be
I have a project for a class which requires that if a database is
I have a project of mine, written in C++, that has now progressed to
As a project I have been working on has grown, so has the frequency
I have a project that requires the following. Four arrays will be declared in
I have a project that requires some configuration files. I want to keep the
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that

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.