javascript - Lazy loading modules with angularjs and requirejs -


i have been tackling issue long time great difficulty since there lot of articles show how load directives, services, , other angular components use word module describe them.. ending seo nightmare.

all solutions incredibily complex, making dividing js files not relevant.

has found simple way inject angular module dependency main module when it's needed ?

note: since i'm using require.js actual js present (also lazyloaded when it's needed). needed inject modules onto angular.

here how close got:

  1. window function in index.html load secondary .js file

    <script type="text/javascript">     var hasbackloaded = false; function loadbackofficejs (cb) {     console.log("loadbackofficejs");     if(!hasbackloaded){         var newscript = document.createelement('script');         newscript.type = 'text/javascript';         newscript.src = '<%=dist_cdn%>/scripts/back.js';         newscript.onload = backloaded;         document.body.appendchild(newscript);         function backloaded(){             console.log("back loaded")             hasbackloaded = true;             cb();         }      } else {         cb();     } } 

  2. call previous function , try load angular modules angular

    loadbackofficejs(function(){ require(['back'], function(){ //angular modules should injected here.. somehow }); });

you should take @ lib oclazyload

most basic usecase load module provided $oclazyload service.

$oclazyload.load('yourmodule.js'); 

this article written lib's author when started library. though it's bit old it's entry point internals of lazy loading modules.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -