Search code examples
javascriptangularjsangular-ui-routerlazy-loadingangularjs-routing

How lazy load js scripts synchronously?


I'm trying to find a tool or a .js lib to lazy load my scripts on demand of the routes/urls'.

Basically, I want to:

state = {
  state: 'widgets',
  config: {
     url: '/',
     templateUrl: 'modules/widgets/templates/widgets.template.html',
     resolve: {
         // load the .js  somehow
     }          
}
$stateProvider.state(state.state, state.config);

have anyone already done that? or is there a stand for lazy load .js files?

Thanks!


Solution

  • Probably not exactly what you need, but yes, you can use $controllerProvider. you can find a very nice article here that explains lazy loading in angular - http://ify.io/lazy-loading-in-angularjs/

    check this out - AngularJS: lazy loading controllers and content and the lazy load library https://oclazyload.readme.io/