Question

I am currently writing a example application with require.js and now found LazyLoad.js.

Require.js

require(["modul1", "modul2"],function(Modul1, Modul2){

LazyLoad.js

LazyLoad.js(["modul1", "modul2"],function(Modul1, Modul2){

Where is the difference between these both?

For me it is important to be able to load modules async and the dependency management should be done automatically.

Était-ce utile?

La solution

If you want automatic dependency management then LazyLoad is not appropriate. LazyLoad is appropriate if you just need a runtime loader and don't care about:

  1. Defining modules
  2. Tracking dependencies. From the lazyload github (emphasis mine):

    Use LazyLoad when you need a small, fast, safe dynamic JS or CSS loader, but don't need the overhead of dependency management or other extra functionality that larger script loaders provide.

  3. An option for build-time optimization
It looks like LazyLoad just directly loads URLs and doesn't check for path mappings or if that module is already loaded. So I think your 2nd code snippet would probably look like this:

LazyLoad.js(["some/path/modul1.js", "some/path/modul2.js"],function(Modul1, Modul2){

Whereas RequireJS would let you do something like this:

   require.config({
       paths: {
           modul1: 'libs/module1/blah.1.3.3-min',
           modul2: 'libs/module2/foo.2.7.2-min',
       }
   });

   require(["modul1", "modul2"],function(Modul1, Modul2){

And also define shims for what files need to be loaded before these modules.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top