ocLazyLoad
ocLazyLoad copied to clipboard
Random issue when using using $ocLazyLoad in ui-router resolve
I use ocLazyLoad with ui-router:
.state('view', {
url: '/view/:id',
parent: 'app',
templateUrl: 'app/view/view-template.html',
controller: 'viewCtrl',
abstract: true,
resolve: {
viewResolve: function(Restangular, $stateParams) {
return Restangular.one('qInfo', $stateParams.id).withHttpConfig({
cache: false
}).get();
},
viewJsFile: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'viewCtrl',
files: ['resources/scripts/view.js']
});
}]
}
})
Sometimes I experience browser freezing (Not Responding appears on title bar) for about 3-5 seconds, then the js file loads successfully and app continues working fine!
I checked the timing for loading view.js
: in the normal situation it's 3 ms (milisecconds), but in the error situation it's about 500 ms!
Any ideas?
it loads js files by appending
@ocombe I guess your comment is incomplete!
oh yes, weird I was saying: it loads js files by appending a script tag into the page, which is async. The only synchronous parts that could block the page are: generating a complete hash of the code (but it's supposed to be fast), and when the page itself executes the code of the script tag, if you have a really long script or long synchronous operations inside this script tag. What I don't understand is why it would sometimes take 3ms and sometimes 500ms