Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript获取时间与XHR网络时间_Javascript_Performance_Api_Fetch Api - Fatal编程技术网

Javascript获取时间与XHR网络时间

Javascript获取时间与XHR网络时间,javascript,performance,api,fetch-api,Javascript,Performance,Api,Fetch Api,我有一个javascript的基本代码,可以通过api调用获取数据: var t0 = performance.now(); fetch( 'http://domain/service', { method: 'GET' } ) .then( response => { //handle response... t1 = performance.now(); console.log('Call to fetch-start t

我有一个javascript的基本代码,可以通过api调用获取数据:

var t0 = performance.now();
fetch(
    'http://domain/service',
    { method: 'GET' }
  )
  .then( response => {
      //handle response...
       t1 = performance.now();
       console.log('Call to fetch-start took ' + (t1 - t0) + ' milliseconds.');
    } )
  .catch( error => console.error('error:', error) )
  .then( () => {
       ...
       t1 = performance.now();
       console.log('Call to fetch-end took ' + (t1 - t0) + ' milliseconds.');
    } );
当我调用它时,Chrome网络时间显示如下:

但控制台显示如下:

Call to fetch-start took 1931.162 milliseconds.
Call to fetch-end took 2846.36500000488 milliseconds.

我不理解浏览器网络时间和获取时间之间的区别。它们应该是相同的?

这是因为当
fetch
与Body对象解析时,只完成了头的协商和获取。
数据的提取仍在进行中,这就是我们可以做到的


最接近提取实际结束的将是
Body.arrayBuffer()
,它不会对提取的数据执行任何转换。

这是因为当
fetch
与Body对象解析时,只完成了头的协商和提取。
数据的提取仍在进行中,这就是我们可以做到的


最接近实际抓取结束的是
Body.arrayBuffer()
,它不会对抓取的数据执行任何转换。

看起来像
response.json()
花费了很多时间?旁注:这不是问题,但像许多人一样,您正在遇到问题。您需要检查
response.ok
。看起来
response.json()
花了很多时间?旁注:这不是问题所在,但与许多人一样,您遇到了问题。您需要检查
响应。ok