I'm loading an Angular app and loading some initialisation data using a <script src="/init">
call.
I found that Chrome wasn't starting the Angular $compile process until all javascript scripts were loaded, including the /init
call, which might take a long time.
So to make the Angular compile process begin before /init
returns I added async
, thus <script src="/init" async>
, which gets that desired result.
However, there is a strange problem with async
(only in Chrome it seems), whereby if async
is added, Chrome doesn't request that resource until after all other resources listed on the page have loaded (not Angular ng-includes
etc, just the regular ones with src
and href
attributes).
Here's the network results in DevTools without async
. The LAST one is the /init
call, and the ones before it are script tags calling Angular code
Here's with async
The last bar is the <script src="/init" async>
one. If you ask me, the async script has been loaded synchronously (as in, in sequence).
So have I misunderstood how async
works? Or is this a bug in Chrome (Version 40.0.2214.94 m on XP)? I'm guessing the latter, because Firefox kicks off all script loads regardless of async
as I'd expect.
UPDATE: Chrome team intentionally reduced the priority of async script load, so my problem isn't a bug at all. It's a feature! :)