AJAX requests Synchronous Vs Asynchronous

假如想象 提交于 2019-11-30 23:01:01

问题


Is there any difference in performance ( speed wise ) between a synchronous request and and asynchronous request?

What all are the reasons for using an asynchronous request??


回答1:


You should mostly always use an asynchronous Ajax Request, in fact I know only about one place where a synchronous Ajax Request should be used which is if you're in an Ajax Request embedding a new JavaScript file on the client and then referencing types and/or objects from that JavaScript file in the return from the original Ajax Request. Then the fetching of this new JS file should (or can sanely) be included through using a synchronous Ajax Request...

Other then that you should always use asynchronous Ajax Requests. The most important reason is that a synchronous Ajax Request makes the UI (browser) unresponsive...




回答2:


@Thomas Hansen answer is right but I found a clear explanation with benefits of Asynchronous.

Synchronous is simple, but wait for the server response, thus block the execution of the caller for a period and slower than asynchronous while processing the request.

Asynchronous is required setting, do not wait after submitting the request and immediately return control to the caller, thus faster than Synchronous.

I am coming here when I have to use upload control which has both functionalities in the question and looking the pros and cons of this functionality.

I got the another link which explained with a real example. (the link is the specific tool, so understand the logic)

  • The major difference is the response time from our servers. At the time of upload, synchronous will validate file and create the passcode in real-time. Asynchronous will send the file to our server's queue and deliver notification via email once it is processed.

  • Synchronous is not ideal for multiple, large CSV file since you will need to wait until the file is processed by the server to submit another request. On large files, this also may cause your browsers to return with timeout errors due to the server being too busy. If you have multiple files, asynchronous will allow you to submit multiple files to the server queue to be processed with a email receipt once completed.

https://www.aspsnippets.com/Articles/Difference-between-Synchronous-Sync-and-Asynchronous-Async-Request-Call-in-AJAX.aspx




回答3:


there can be serious performance implications caused when it come to highly database intensive applications .. although it's very unlikely to happen .. and sending many Synchronous ajax calls can create a backlog .. so if the application database intensive and sending so many request at once it is better to make it asynchronous. when its set to asynch the browser will fail all unresponsive request and continue with new once..



来源:https://stackoverflow.com/questions/1052453/ajax-requests-synchronous-vs-asynchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!