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.
In my main app everything is triggered by this script tag:
<script data-main='/scripts/main' src='/scripts/libs/require.js'>
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 main.js package. I am struggling to understand where the rest of my site fits into this.
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 main.js just to get access to my jQuery module. So yeah... a little confused!
I am imagining a site structure sort of like this:
/scripts
- app-main.js //(includes all module dependencies after optimzation)
- home-main.js //(includes all module dependencies after optimzation)
App:
<script data-main='/scripts/app-main' src='/scripts/libs/require.js'>
Homepage:
<script data-main='/scripts/home-main' src='/scripts/libs/require.js'>
Questions
- How can I use RequireJS to develop different parts of a site?
- Is it recommended to have multiple main.js files?
- How can my different
main.jsfiles share common modules such as jQuery post optimization?