소스 검색

HUE-8458 [frontend] Evaluate the js resources while others are being fetched

Instead of waiting for all the get requests to finish it will now wait for them in order and evaluate while others are being loaded.
Johan Ahlen 7 년 전
부모
커밋
e2b3ada
1개의 변경된 파일22개의 추가작업 그리고 11개의 파일을 삭제
  1. 22 11
      desktop/core/src/desktop/templates/hue.mako

+ 22 - 11
desktop/core/src/desktop/templates/hue.mako

@@ -786,14 +786,14 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
             if (loadedJs.indexOf(scriptUrl) !== -1) {
               continue;
             }
-            var deferred = $.Deferred();
-            promises.push(deferred.promise());
-            deferred.always(function () {
+            var loadDeferred = $.Deferred();
+            promises.push(loadDeferred.promise());
+            loadDeferred.always(function () {
               loadedJs.push(scriptUrl);
             });
-            $.get(scriptUrl).done(deferred.resolve).fail(function () {
-              // Ignore failed ones, they appear in the dev tools
-              deferred.resolve('');
+            $.get(scriptUrl).done(loadDeferred.resolve).fail(function () {
+              // Ignore failed ones, they'll still appear as failed in the network tab as before
+              loadDeferred.resolve('');
             });
           }
           return promises;
@@ -850,12 +850,23 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
           $rawHtml.unwrap('<span>');
 
-          $.when.apply($, scriptPromises).done(function () {
-            for (var i = 0; i < arguments.length; i++) {
-              eval(arguments[i]);
+          var evalScriptSync = function () {
+            if (scriptPromises.length) {
+              // Evaluate the scripts in the order they were defined in the page
+              var nextScriptPromise = scriptPromises.shift();
+              nextScriptPromise.done(function (contents) {
+                if (contents) {
+                  eval(contents);
+                }
+                evalScriptSync();
+              });
+            } else {
+              // All evaluated
+              promise.resolve($rawHtml);
             }
-            promise.resolve($rawHtml);
-          });
+          };
+
+          evalScriptSync();
           return promise;
         };