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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:30:15+00:00 2026-06-17T04:30:15+00:00

I’ve been looking at require.js and I am a bit confused on how to

  • 0

I’ve been looking at require.js and I am a bit confused on how to use it for my widgets system.

My widgets system basically allows the user to choose which widget s/he wants to see which gets stored in the database.

So when the user loads the page on the next visit, s/he will see only the widgets s/he selected. In effect only loading the html, javascript needed for the displayed widgets instead of loading all the html and javascript for all the widgets and then hidding the stuff which is not needed.

What I am confused about is how to do this with require.js

Am I supposed to dynamically generate the require.js code below? If the user has saved widget_1, widget_5 and widget_70, I am assuming I need to dynamically generating javascript like so?

require(['widget_1','widget_5','widget_70'], function(w1, w5, w70){
    // then do something here?
});

the require line, is that supposed to be dynamically generated based on an sql query?

So if they only select a single widget to save for next time viewing, they will only get:

require(['widget_90'], function(w90){
    // then do something here?
});

Is that what I am supposed to be doing?

  • 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-17T04:30:16+00:00Added an answer on June 17, 2026 at 4:30 am

    Always define path’s to the libraries that your modules rely on too often, something like below:

    <script data-main="scripts/main" src="scripts/require.js"></script>
    

    File: scripts/main.js

    require.config({
        paths: {
            jQuery_1_7_2: 'lib/jquery.1.7.2',
            underscore: 'lib/underscore',
            .....
            .....
        }
    });
    

    Note: You need to include libraries with-in a module and return as an object, something like below:

    File: lib/jquery.1.7.2.js

    define([ 'lib/jquery/jquery.1.7.2.min' ], function() {
    
        return jQuery.noConflict(true);
    
    });
    

    Same approach can be followed for other libraries that does not follow modular approach [AMD spec]

    Note: The above step of defining library modules can be avoided by using shim feature

    Since your page is dynamic, you never know what modules will be loaded.

    You can invoke multiple require() calls to load modules. Since requirejs load’s scripts asynchronously, the below approach will not harm your page performance.

    Module-1 with in HTML view

    <html>..
    <div id="module_1">
        //contents of module 1
    </div>
    <script type="text/javascript">
        require(["scripts/widgets/module_1"], function( module_1 ){
            module_1.init();
        })
    </script>
    ..</html>
    

    File: scripts/widgets/module_1.js

    define(["jQuery_1_7_2","underscore"], function($, _){
        // Module functionality goes here
        return {
            init: function(){
                // Module initialiser
            }
        }
    });
    

    Module 2 with-in HTML view

    <html>..
    <div id="module_2">
        //contents of module 2
    </div>
    <script type="text/javascript">
        require(["scripts/widgets/module_2"], function( module_2 ){
            module_2.init();
        })
    </script>
    ..</html>
    

    File: scripts/widgets/module_2.js

    define(["jQuery_1_7_2","underscore"], function($, _){
        // Module functionality goes here
        return {
            init: function(){
                // Module initialiser
            }
        }
    });
    

    If you do not mind initializing the module after DOM load, you could use controljs and change the MIME type of the script tags. I believe that would not make too much of difference on the page performance.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to run a str_replace or preg_replace which looks for certain words
I want use html5's new tag to play a wav file (currently only supported
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.