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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:55:07+00:00 2026-06-15T02:55:07+00:00

How can you use RequireJS, and have some common JavaScript code for all pages?

  • 0

How can you use RequireJS, and have some common JavaScript code for all pages? If I have a script tag with datamain in the template (used on all pages), can I then have a require(…) on the other pages that requires what they need? Would this cause problems with the sequence of loading? It would right? I also thought having a second script tag in the template that have all the common code (which is outside of RequireJS) hands. Is that the only approach?

  • 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-15T02:55:08+00:00Added an answer on June 15, 2026 at 2:55 am

    strong text> How can you use RequireJS, and have some common JavaScript code for

    all pages?

    The answer to this question will help – How does RequireJS work with multiple pages and partial views?

    can I then have a require(…) on the other pages that requires what
    they need? Would this cause problems with the sequence of loading? It
    would right?

    Nope, this is fine. You can make calls to the same module if you wish and it will only be loaded once. A common example is multiple require calls all needing jquery. You would require it each time to be sure of it’s presence, but there is no penalty as RequireJS is smart enough to fetch it just the once.

    Edit to answer comment:
    Request jQuery and/or jQuery UI as dependencies to either define or require and the callback will execute afterwards:

    require(['jquery', 'jquery-ui'], function($) {
        // jQuery is passed in as first argument but as jquery-ui
        // merely augments jQuery we don't need it as the second argument
    });
    

    This is the real fundamentals of RequireJS (requiring dependencies and executing code when they’re ready) so it might be worth having a detailed read of the documentation (which is superb).

    Last thing to note, is that you will need to set a path to jQuery in your paths configuration and I’m not sure if jQuery UI registers itself as a module. If not, you’ll need to make use of the shim config option

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

Sidebar

Related Questions

I can use the PRINT statement in a stored procedure to debug my code.
I'm trying to use some off-the-shelf PHP code in RHEL5 which requires the sqlite
I have a fairly involved LispWorks Common Lisp module that sits atop some .NET
I'm writing a bunch of web services which all share some common patterns. For
Okay, I need some help here. This is the same old "can't use an
I have some test classes that are making use of spring-batch, and hibernate. My
I have to use some dates and times from a legacy database. They are
I have a common unit that does some logging to GExperts Debugger and/or OutputDebugString.
How can you use jQuery to include/require a different php file if window height
I can use the following to get the contents of a folder with no

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.