Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to optimize requireJS application setup?
    primarykey
    data
    text
    <p>I have a working application using <code>requirejs</code>, which I'm trying to optimize. I'm launching the application in 2 steps:</p> <p>First I start with a setup file <code>setup.js</code>, which I'm calling from the page source code:</p> <pre><code>&lt;script data-main="../js/setup" src="../js/l/require/require.js"&gt;&lt;/script&gt; </code></pre> <p>This file contains my require setup</p> <pre><code>var IS_LOCAL = /(:\/\/localhost|file:\/\/)/.test(document.location.href); requirejs.config({ waitSeconds: (IS_LOCAL ? 2 : 45), baseUrl: "../js", paths: { intro: 'intro', overrides: 'overrides', jquery: 'l/jquery/jquery-1.8.2.min', mobile: 'l/jquery-mobile/jquery-mobile-1.3pre.min', multiview: 'p/multiview/multiview.min', respond: 'p/respond/respond.min', i18next: 'p/i18next.min.js' }, shim: { 'overrides': { deps: ['jquery'] }, 'mobile': { deps: ['jquery'] }, 'multiview': { deps: ['jquery', 'mobile'] }, 'respond': { deps: ['jquery'] }, 'i18next': { deps: ['jquery'] } } }); // launch application - works, but I'm not happy with it requirejs('overrides','jquery','mobile','multiview','respond','i18next','intro'], function (overrides, $, mobile, multiview, respond, i18next, Intro) { 'use strict'; Intro.start(overrides, $, mobile, multiview, respond, i18next); } ); </code></pre> <p>This "triggers" my application controller <code>intro.js</code>, which looks like this:</p> <pre><code>define([], function () { 'use strict'; var start = function () { require(['overrides','jquery','mobile','multiview','respond','i18next'], function () { // stuff } ); // end require } // end start return { "start": start }; }); </code></pre> <p>I'm still figuring out my way with requireJS, so while the above initializes correctly, I'm not sure if this is the best way to handle. Specifically I'm wondering:</p> <p><strong>Questions:</strong><br> 1) In my setup.js file, I'm triggering <code>Intro.start()</code> with plenty of parameters. Do I need the parameters there or should I put them inside <code>intro.js</code> when I'm doing my second require call?<br> 2) Do I need the first require at all, because I'm requiring all files and then trigger a "file" (intro), which requires everything again?<br> 3) How do I make objects available in intro.js? Say I need the <code>i18next</code> object inside <code>intro.js</code> to do some manual translations. Do I export in the shim and pass along through my two requires?</p> <p>Thanks for some insights!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload