简体   繁体   English

Javascript-取消的请求会影响性能吗?

[英]Javascript - will a canceled request affect performance?

Our application is using angular and get a lot of requests. 我们的应用程序使用的是Angular,并收到很多请求。 There is a group of request (Request BCD) has dependency on watching data returned by another request.(Please see attachment) So when first load the page, it will send BCD requests and A request was sent at same time. 有一组请求(Request BCD)依赖于监视另一个请求返回的数据。(请参阅附件)因此,当第一次加载页面时,它将发送BCD请求,并且同时发送了一个请求。 When A request returned data, BCD request will send again and the earlier BCD request will be abort(Canceled). 当一个请求返回数据时,BCD请求将再次发送,并且先前的BCD请求将被中止(取消)。

My question is: since the request was canceled anyway, will this affect my page loading time? 我的问题是:由于请求仍然被取消,这会影响我的页面加载时间吗? Should I implement something like a promise to let BCD request wait for A request finish then watch data returned from A request? 我是否应该实现诸如使BCD请求等待A请求完成然后监视A请求返回的数据之类的承诺?

Screen shoot 1 屏幕截图1

There will be additional work as engine will have to perform certain actions to cancel request. 由于引擎必须执行某些操作才能取消请求,因此将会有其他工作。 You can find steps here 您可以在这里找到步骤

As you see engine will have to fire following events: 如您所见,引擎将不得不触发以下事件:

  • readystatechange readystatechange
  • progress 进展
  • abort 退出
  • loadend loadend

Along with updating some flags. 随着更新一些标志。 But these work will take very less time and delay in performance would be negligible. 但是这些工作将花费很少的时间,并且性能的延迟可以忽略不计。


Edit 1: 编辑1:

If you refer concept-event-fire-progress , mentioned events will be fired anyways except abort . 如果您引用concept-event-fire-progress ,则提及的事件将始终被触发,但abort除外。 It would be error or load or timeout based on status. 根据状态,可能是errorloadtimeout But cancelling a request would make engine fire these events right away and this might add some time. 但是取消请求会使引擎立即触发这些事件,这可能会增加一些时间。 But again, the total time will be negligible. 但是同样,总时间可以忽略不计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM