Re:Managing Async Dependencies with JavaScript
by jhabdas on Sunday May 21, 2017 @09:06AM
(#14387112)
WRT performance, fetch is a newer standard and still getting ironed out. Browsers have been using external scripts for years and know how to handle them efficiently. A downside to using `script` tags however, is they have to be on the page when the document is loaded, and they block the browser run loop.
I naively thought that it would be quicker to have an inline <script> (coming first in the <head>) and have the script request JavaScript resources via XHR (to manage resource dependencies and load failures).
However, the browser decides the priority for resource requests and CPU usage. I found that XHR requests got low priority and wouldn't even get requested until after painting delays.