ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

oclazyload using $routeProvider to lazy load files via routes #385

Open bigbriggy opened 7 years ago

bigbriggy commented 7 years ago

I have recently added ocLazyload to an angular 1.3 project and I am lazyloading controller js files when navigating around the site as opposed to loading them upfront. Everything works well for the most part however I am noticing that on some routes that when it goes to load the controller it will display my loading bar temporarily (as expected as im making other service calls at the same time) and it displays the initial view again before moving to the new view whose controller js file we lazy loaded.

This gives us an inconsistent user experience - If I roll back to loading all my files upfront as the only change this behavior never occurs - is there anything I should be looking out for to help identify what could be going on?

Example route where I see the behaviour

.when('/Test/profile', {
             templateUrl: '/App/Test/Profile/ProfilePartial.html',
             controller: 'ProfileController',
             resolve: {
                 lazy: ['$ocLazyLoad', function ($ocLazyLoad) {
                     return $ocLazyLoad.load([{
                         name: 'MyApp',
                         files: ['App/Test/Profile/ProfileController.js',
                                'App/Test/Profile/Addresses/AddressesController.js']
                     }]);
                 }],
                 userProfileData: ['dataservice', function (dataservice) {
                     return dataservice.callService('get', 'api/Test/GetProfileData', null, false);
                 }]
             },

Many thanks