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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:53:03+00:00 2026-06-16T13:53:03+00:00

I am interested in creating a single configuration object for all the JavaScript code

  • 0

I am interested in creating a single configuration object for all the JavaScript code on my Web site. I found https://github.com/requirejs/example-multipage-shim which is an example of this setup.

From https://github.com/requirejs/example-multipage-shim (emphasis
mine): Since the shim config requires dependencies to be in the page,
instead of using data-main=”js/page1″ for page1.html, this example
inlines the require calls in the HTML page. If data-main was used
instead, then ‘js/page1’ could not have any dependencies inlined
,
and instead still rely on the ‘common’ and ‘app/main1’ build layers to
hold the modules, due to the restrictions shim config places on the
build.

I do not understand the bolded sentence. Does it mean that “js/page1” if it existed could not declare dependencies? What does it mean to have a dependency inlined? Inlined into what? The HTML file or the JavaScript file?

I read the API doc about shim config, but the limitations that it puts on the optimizer is not clear.

From https://github.com/requirejs/example-multipage-shim/blob/master/www/page1.html:

    <script src="js/lib/require.js"></script>
    <script>
        //Load common code that includes config, then load the app
        //logic for this page. Do the require calls here instead of
        //a separate file so after a build there are only 2 HTTP
        //requests instead of three.
        require(['./js/common'], function (common) {
            //js/common sets the baseUrl to be js/ so
            //can just ask for 'app/main1' here instead
            //of 'js/app/main1'
            require(['app/main1']);
        });
    </script> 

Why is the following wrong? Why does “app/main1” have to be in a separate module from the bootstrap (data-main) code?

    <script src="js/lib/require.js"></script>
    <script>
        require(['js/common'], function (common) {
            var underscore = require('underscore');
            // ...
        });
    </script> 
  • 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-16T13:53:05+00:00Added an answer on June 16, 2026 at 1:53 pm

    It is a good practice to define (with define) each module in a separate javascript file. Otherwise it doesn’t make sense to load the several modules asynchronuously, because the are in the same physical location. In most cases, you’ll only need to use function define. Only in your bootstrapping module, you’ll need to use function require.

    When I’m using require.js, I have 1 module (bootstrap.js), which contains my require.config object and the initial bootstrapping. In the html page you only need to include 1 script: require.js with bootstrap as data-main attribute value:

    HTML:

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

    bootstrap:

    require.config = {
       baseUrl: 'js',
       paths: {
         ...
       },
       shim: {
       }
       ...
    };
    
    // initial bootstrap
    require(['jquery', 'angular', 'app'], function($, angular) {
       // do bootstrap
    });
    

    Modules:

    define(['jquery'], function($) {
       // do sth with app
    });
    

    Edit: misunderstood the question a bit.

    The reason that you cannot use inline dependencies in the html page when using the data-main attribute is that it like likely fail to load them. Which code block will be executed first? The data-main bootstrapping js or the inline code? If your bootstrapping js file will load first and set the baseUrl to 'js', the inline code should use require('common') instead of require('js/common'). But if the inline code loads first, it has to be require('js/common').

    The reason why require('app/main1') is inside the other require block is the same: module ‘common’ will change the baseUrl to 'js'. Also ‘app/main’ probably needs some of the shim config from ‘common’. This is the only way to make sure the common module (with the shim config) is loaded first.

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

Sidebar

Related Questions

I am interested in creating a web app that uses JSP , Servlets and
I am interested in creating a simple web application that will take in user
I'm creating a multi-user/company web application in PHP & MySQL. I'm interested to know
I am interested in creating a web page editor like the one used in
I'm interested in creating an alternate version of a Wordpress site, specifically tailored for
I'm interested in creating some web apps that simulate results based on data. For
I'm primarily an Android developer, but I'm very interested in creating web pages in
I'm interested in creating a custom theme for a Drupal site I'm working on.
I'm interested in creating a TypeTag manually (since 2.10M5): object X { import reflect.runtime.universe._
I'm interested in creating a text-based game similar to Zork . The source code

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.