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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:40:31+00:00 2026-06-04T17:40:31+00:00

Is there a preferred way to pass server data in a RequireJS module? Our

  • 0

Is there a preferred way to pass server data in a RequireJS module? Our current implementation looks like the following code snippets; using a ‘page’ object to hold any server/dynamic data and passing that to the main bootstrap. (We don’t want to use ajax to populate any dependencies at this time)

From a server page :

<script data-main="scripts/main" src="scripts/require-jquery.js"></script>
<script type="text/javascript">
  define("page", function () {
      return { guid: "<%=Guid.NewGuid() %>" };
    });
</script>

main.js

require(["jquery", "jquery.alpha", "page"], function ($, alpha, page) {
    alpha.initialize(page);
});

jquery.apha.js

define(["jquery", "page"], function ($, page) {
    return {
        initialize: function () {
            console.log(page.guid);
            //logs guid as expected
        }
    }
});
  • 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-04T17:40:32+00:00Added an answer on June 4, 2026 at 5:40 pm

    RequireJS says nothing about how to deal with server data, as it is a means to modularize your javascript. So in that regard there is no defacto standard and you can combine RequireJS with json, ajax, php, embedded xml etc however you want.

    Two Approaches

    There generally are two ways to go about this.

    1. Model a ‘dao’ or ‘service’ module that gets the required data from the server and
      makes it accessible to its users (similar to your current approach, see code sample below)
    2. Define a global object to which all modules have access

    The first approach adds parameters to your functions.

    The second provides global access. This also requires your own initialization code to start fetching data.

    It comes down to personal preference and how many of these ‘dao’s’ you have. If you have more than one it might become poluting as you need a new parameter for each dao module. In that case making them global seems cleaner.

    A problem with your approach

    There is a problem with your current approach though, where you have the Page module as a definition (using define() instead of require()), because a define module is created for each object that depends on it. This potentially means multiple calls within the same page. Instead use:

    // in seperate file page.js:
    require([], function () {
      return { guid: "<%=Guid.NewGuid() %>" };
    });
    

    This way RequireJS recognizes page as a module because it is a seperate file and it will go to your server only once per page.

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

Sidebar

Related Questions

Is there a preferred (not ugly) way of outputting a list length as a
Is there a (or, do you have your own) preferred way to do background
Given two lists of equal length, is there a simpler or preferred way to
Is there any reliable and simple priority queue (linked list preferred, not necessary) implementation
Is there a preferred way? There are currently 1640 rows in the game table
Is there some preferred way to organize ones include directives? Is it better to
Is there a preferred way to return multiple values from a C++ function? For
Is there a preferred way to create a hierarchy of new ActiveRecord model objects
Is there a preferred way to go about this? The app in question is
In ASP.NET WebForms I want to pass arbitrary data from server to client and

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.