ocLazyLoad icon indicating copy to clipboard operation
ocLazyLoad copied to clipboard

Random issue when using using $ocLazyLoad in ui-router resolve

Open mahmoudmy opened this issue 8 years ago • 3 comments

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?

mahmoudmy avatar Aug 23 '16 08:08 mahmoudmy

it loads js files by appending

ocombe avatar Aug 23 '16 08:08 ocombe

@ocombe I guess your comment is incomplete!

mahmoudmy avatar Aug 23 '16 08:08 mahmoudmy

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

ocombe avatar Aug 23 '16 08:08 ocombe