Note that there are some explanatory texts on larger screens.

plurals
  1. PORequireJS: Multiple main.js?
    primarykey
    data
    text
    <p>I have been building a single page app using requireJS and so far loving it. I have come to the point of developing other parts of the site outside of the main app and am not really sure how (or if) to use requireJS for this.</p> <p>In my main app everything is triggered by this script tag:</p> <pre><code>&lt;script data-main='/scripts/main' src='/scripts/libs/require.js'&gt; </code></pre> <p>I am now developing the home page which has it's own front end scripts. Using the optimizer when it comes to getting the site live which will bundle all these scripts into one <code>main.js</code> package. I am struggling to understand where the rest of my site fits into this. </p> <p>Say my app is dependent on jQuery and it gets bundled up in the optimized version of the app, what if I want to use jQuery on the homepage? I don't want to load in my app's <code>main.js</code> just to get access to my jQuery module. <strong>So yeah... a little confused!</strong></p> <p><br> <strong>I am imagining a site structure sort of like this:</strong></p> <pre><code>/scripts - app-main.js //(includes all module dependencies after optimzation) - home-main.js //(includes all module dependencies after optimzation) </code></pre> <p>App:</p> <pre><code>&lt;script data-main='/scripts/app-main' src='/scripts/libs/require.js'&gt; </code></pre> <p>Homepage:</p> <pre><code>&lt;script data-main='/scripts/home-main' src='/scripts/libs/require.js'&gt; </code></pre> <p><br> <strong>Questions</strong></p> <ol> <li>How can I use RequireJS to develop different parts of a site?</li> <li>Is it recommended to have multiple main.js files?</li> <li>How can my different <code>main.js</code> files share common modules such as jQuery post optimization?</li> </ol>
    singulars
    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.
 

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