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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:14:46+00:00 2026-06-18T10:14:46+00:00

In the RequireJS example, it shows that you can reference a app.js (or whatever

  • 0

In the RequireJS example, it shows that you can reference a app.js (or whatever you want to call the starter file) from the script tag like so:

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

For reasons beyond my control, I can’t do this. There are several dynamic variables generated in the template layer that need to be preserved. So, I created an inline ‘config’ module that other modules can read.

<script type="text/javascript">
        define('config', function() { 
            return {
                markup_id: {
                    "content": "search",
                    "page": "index",
                    "media": "mobile"
                },
                page_context: {
                    "siteconfig": {
                        "mobile_video_player_id": /* */,
                        "mobile_video_player_key": /* */,
                        "mobile_ad_site": /* */,
                        "omniture_mobile_env": /* */,
                        "searchserver": /* */,              
                    },
                    "omniture": {
                        "gn": /* */,

                    }
                }
            }
        });
    </script>       

What I have done is for each template, I placed an inline require.config. As an example (specific path information removed):

<script type="text/javascript">
/* This code is on a template page inside a script tag. */
require.config({
            baseUrl: /* */,
            paths: {
                'jquery': /* */,
                'jquery-mobilead': /* */,
                'jquery-photogalleryswipe': /* */
            },
            /* Enforce ordering of jQuery plugins - which require jquery */
            shim: {
                'jquery-mobilead': {
                    deps: ['jquery'],
                    exports: 'jQuery.fn.mobileAd'
                },
                'jquery-photogalleryswipe': {
                    deps: ['jquery'],
                    exports: 'jQuery.fn.photoGallerySwipe'
                },
                'gallery': {
                    deps: ['jquery-photogalleryswipe', 'jquery-mobilead']
                }
            },
            urlArgs: 'buildlife=@buildlife@'
        });

        require( ['jquery', 'site', 'gallery', 'jquery-photogalleryswipe', 'jquery-mobilead'], function($, site, gallery) {
                //This function will be called when all the dependencies
                //listed above are loaded. Note that this function could
                //be called before the page is loaded.
                //This callback is optional.

                /* Initialize code */
                $(document).ready(function() {
                    /* sitewide code - call the constructor to initialize */
                    site.init();
                    /* homepage contains a reference to a function - execute the function */
                    gallery.initGallery();
                });
            }
        );
</script>

I presume the Optimizer has no way of optimizing code inside a template.

However I do have module JS files in accordance to the RequireJS API documentation.
/modules/gallery.js
/modules/channel.js
/modules/site.js
/* etc. */

These modules do have dependencies to other modules, but these modules are dependent on the ‘config’ module, which is defined inline with the template. If I ran the Optimizer against these files, will the optimizer work properly, since one of the modules, config, in is the template?

  • 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-18T10:14:47+00:00Added an answer on June 18, 2026 at 10:14 am

    I think I solved my own problem based on reading
    How to load bootstrapped models in Backbone.js while using AMD (require.js)

    I’ve restructured the template variables into a require global object and declared it before require.js. Now, the template can still generate those values, but since the require.config and require code can be put into an external JS file, the optimizer should be able to see those files now. I haven’t tried running the optimizer yet.

    <script>
            /* This script block is in the template */
            var require = {
                config: {
                    markup_id: {
                    "content": "search",
                    "page": "index",
                    "media": "mobile"
                    },
                    page_context: {
                       "siteconfig": {
                        "mobile_video_player_id": /* */,
                        "mobile_video_player_key": /* */,
                        "mobile_ad_site": /* */,
                        "omniture_mobile_env": /* */,
                        "searchserver": /* */,              
                      },
                    "omniture": {
                        "gn": /* */,
    
                    }
                }
            };
        </script>
     <script data-main="/m/j/main-search" src="/m/j/require.js"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have that script: // ==UserScript== // @name example // @include http://xxx* // @require
I am trying to find a simple bare bones example/demo that shows me how
The goal: To create a .NET dll i can reference from inside SQL Server
required( dependency-expression ) They give an example of required: #other:checked but I want my
For example I want to use custom logger: logger = require('basic-logger'), logger.setLevel('info') var customConfig
Say that I require a querystring; for example itemid. If that querystring is for
Should I include/require_once the parent class that I am extending in PHP? for example
Is there an existing function that creates confidence intervals from a svyby object for
Does anybody know of a diff-like tool that can show me the changes between
Is there some library or generator that I can use to generate multiple templated

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.