Search code examples
requirejsbundleamdsingle-page-application

SPA using BundleConfig and Require.js


I would appreciate any reasonable explanation of the use of BundleConfig and Require.js together in a SPA. How do you choose which scripts should be loaded by BundleConfig when starting the app? Which scripts should NOT be called in BundleConfig and selectively loaded via AMD? Once loaded by BundleConfig, do they have to be called again in require.js' DEFINE statement?

Search as I might, I simply can't find a simple explanation for all this.

Thanks!


Solution

  • BundleConfig will help you get all the script sin the bundle to the client together, in 1 trip. This takes the burden or job off of require.js for that. I often do this for 3rd party scripts, since it is highly likely i need them all client side right away anyway.

    Then I can choose to either use require.js to load my scripts as needed (thus AMD) or bundle them too, up front.

    Require does not just load things asyncly, though. It also handles the dependency resolution. To me, this is the more important part. It makes sure before I use module A that if it depends on B, which depends on C, which depends on D is resolved first. So they get loaded and run in the proper order.

    So whether you use bundling or not, the require.js dependency aspects as super valuable.