Wizard
Wizard

Reputation: 11265

RequireJs optimal way to load modules

My app structure is:

**module1**
page1.html
module2.js
**module2**
page2.html
module2.js

I trty solve problem - find best way to 'require modules' My solution: In page1.html

include require.js

<script>
require.config ...
require([page1])
</script>

It's optimal way to load modules ?

Upvotes: 0

Views: 49

Answers (1)

Tiago Romero Garcia
Tiago Romero Garcia

Reputation: 1078

If you want to go the whole nine yards on optimization, have a look at R.js optimizer, which is part of Require.js.

R.js will group modules in bundles, so that you can still do multiple require() calls and not do multiple HTTP requests.

For instance, if you have 3 modules to be required during page-load time, then you can use R.js to create a bundle containing those 3 modules (automatically including all their dependencies as well).

However, if you have more modules to be lazy-loaded later in the page (let's say, you want some module to be loaded only after the user clicks on a button), then you need to remember to not include those modules on your main bundle, and instead create bundles specific for the lazy-loadable modules.

Upvotes: 2

Related Questions