"Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/"When I look at http://xhr.spec.whatwg.org/ I see this:
Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience.This presumably means that I should find a better implementation, otherwise one day I will suddenly find that my code no longer works.
I like browserify... It's not an implementation of require but another solution to the problem.
Indeed that is difficult: the way most people solve it now is with webpack or browserify, where the requires are done statically, at build time, not at runtime. There's a few modules where that won't work, but for the most part it's a workable way.
You really don't want to be blocking the browser interaction thread, so synchronous is in fact not good there (though you're likely only doing it at startup time), and requests have a real cost in latency, especially unparallelized like a synchronous interface will allow you to do.
I like browserify... It's not an implementation of require but another solution to the problem.
On Tuesday, November 17, 2015 at 7:17:00 PM UTC+2, Aria Stewart wrote:Indeed that is difficult: the way most people solve it now is with webpack or browserify, where the requires are done statically, at build time, not at runtime. There's a few modules where that won't work, but for the most part it's a workable way.OK. I was trying to do it on-the-fly, but I suppose I could look at just bundling everything up, or maybe have different bundles for different situations, or... (sigh).
You really don't want to be blocking the browser interaction thread, so synchronous is in fact not good there (though you're likely only doing it at startup time), and requests have a real cost in latency, especially unparallelized like a synchronous interface will allow you to do.
The only other ideas I had were
(a) to fork it off into a separate thread (which I could do easily in Java, but in JS... maybe use setTimeout? I don't know enough about the JS threading model)
(b) write my own version of "require" which injects a <script> node into the DOM tree and let the browser do the loading rather than using XHR...