On Tuesday, November 17, 2015 at 12:11:02 PM UTC-5, John English wrote: > > I have a bunch of JS which I want to run as a standalone program using > node.js and also within a browser. The code is divided into several file > which are loaded as needed using "require", This works well with node.js, > but not so well in a browser. In the browser I've tried using Smoothie, > which provides a compatible version of "require", but I get a warning: > >> "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/ > <http://www.google.com/url?q=http%3A%2F%2Fxhr.spec.whatwg.org%2F&sa=D&sntz=1&usg=AFQjCNF5wcVPVxgjVws4JdSrEJZoNczDVg> > > 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. > > So, can anyone suggest an implementation of "require" that I can use in a > browser that is > (a) compatible with node.js, and > (b) doesn't break any rules that will lead to trouble in the future? > > Many thanks for any advice... > > 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. It's a set of trade-offs: node went with synchronous IO because it simplified the interface suitably for the use-case, and browser module systems went for pre-building, because of the constraints and latency involved in IO there. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0929fc87-ef37-4786-b91f-f17b393b29c6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
