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

The Archive Base Latest Questions

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

I want to use a separate domain as a JavaScript framework and it will

  • 0

I want to use a separate domain as a JavaScript framework and it will create a base require config which I can augment from the app.

foo.example.com
    main.js
    lib/foo-specific.js
framework.example.com
    framework.js <-- entry point
    lib/jquery.js
    lib/etc...

Optimally, I’d like to be able to require ‘lib/foo-specific’ and/or ‘lib/jquery’ and have the paths just resolve nicely, but from what I’ve found, there’s no way to do this, unless I use a specific path key/value for every js file in the framework. At the moment, I’ve got a custom plugin to load the given path with a different base url (e.g. fw!lib/jquery), though if I wanted to use the text! plugin, it won’t work as plugin chaining is unsupported.

See https://github.com/jpillora/js-framework for what I’ve currently got, and also https://github.com/jpillora/prettyprinter for a use case.

Is there a clean way to solve this ? or to achieve multiple base URLs ?

Note: I have also looked into multiple require instances, though I don’t think that would work as I’d like the the app to be able to access the framework’s config.

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

    Answered by James Burke on RequireJS Github Issue’s page: Issue #447: Multiple Base URLs · jrburke/requirejs.

    Turns out to be quite simple if data-main is the only entry point to your scripts(comments for more info), I solved my particular problem with the following:

    My app’s index.html:

    <script src="http://framework.jpillora.com/js/lib/require.js" 
      data-main="http://framework.jpillora.com/js/framework" > </script>
    

    has the requirejs entry point set to framework.js:

    var framework = ... //set using script elements src attribute
    
    require.config({
    
        baseUrl: 'js/',
    
        //Framework paths
        paths: {
          'framework': framework,
          'lib'      : framework + 'js/lib',
          'ext'      : framework + 'js/ext',
          'util'     : framework + 'js/util'
        },
    
        //Shortcuts
        map: {
          '*': {
            ...
          }
        },
    
        //Non-modularised libraries with deps
        shim: {
          ...
        }
    });
    
    require(['main']);
    

    So instead of normally doing index.html->main.js, we’re adding an extra step index.html->framework.js->main.js, which gives the app code knowledge of paths to the framework code.

    For example, in the app http://prettyprint.jpillora.com/, once require has loaded framework.js, it will setup paths to lib/... which to http://framework.jpillora.com/ and set the baseUrl as ./js/ so once main is required, it will have the base url set to it’s own domain and lib pointing to another domain.

    Which results in require(['lib/foo', 'view/bar']);
    resolving to:

    http://framework.jpillora.com/js/lib/foo.js and
    http://prettyprint.jpillora.com/js/view/bar.js

    As displayed here, the app is only a main.js everything else comes from the framework:

    chrome devtools loaded app

    So finally, whenever I load an app’s main.js via with the above framework.js, I then have access to all of my commonly used libraries and utility classes. See app source.

    Also note, with the r.js optimiser and a nice local file structure, one can also optimise the app into a single js file pulling only what’s required from framework.

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

Sidebar

Related Questions

I have seen many websites use a separate domain, or subdomain to serve javascript
I'm running multiple content/design separate websites from same middleware and I want to use
I develop small fb app (which will be available on separate domain and through
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I
i want use some data from a website with web service. i have a
I want use this 1 for using Bar code or QR code scanner. I
I want use a single php file to handle all of my voting requests.
I want use groovy findAll with my param to filtering closure filterClosure = {
I want use JQuery mobile for the front-end of my mobile application, but I

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.