Asynchronously load scripts with JSX transformer.
Nate Hunzaker committed
May 18, 2014 at 15:17 UTC
bc79f623a17bf3c518107d5dadf6421eb612337e
1 file changed
+12
-5
vendor/browser-transforms.js
+12
-5
@@ -148,9 +148,9 @@ var load = exports.load = function(url, callback) {
148
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
149
: new XMLHttpRequest();
150
151
- // Disable async since we need to execute scripts in the order they are in the
151
+ // async, however scripts will be executed in the order they are in the
152
// DOM to mirror normal script loading.
153
- xhr.open('GET', url, false);
153
+ xhr.open('GET', url, true);
154
if ('overrideMimeType' in xhr) {
155
xhr.overrideMimeType('text/plain');
156
}
@@ -182,13 +182,20 @@ runScripts = function() {
182
183
console.warn("You are using the in-browser JSX transformer. Be sure to precompile your JSX for production - http://facebook.github.io/react/docs/tooling-integration.html#jsx");
184
185
- jsxScripts.forEach(function(script) {
185
+ function tick() {
186
+ if (!jsxScripts.length) return;
187
+
188
+ var script = jsxScripts.shift();
189
+
190
if (script.src) {
187
- load(script.src);
191
+ load(script.src, tick);
192
} else {
193
run(script.innerHTML, null);
194
+ tick();
195
}
191
- });
196
+ }
197
+
198
+ tick();
199
};
200
201
if (typeof window !== "undefined" && window !== null) {