http调用window.performance的大小

Size of an http call with window.performance

本文关键字:performance 调用 window http      更新时间:2023-09-26

我目前保存一些httpCall的持续时间来分析我的web应用程序的性能。我使用window.performance.getEntries(),只获取我需要的调用。

一切都工作得很好,但是我想要得到这个保存的调用的大小。这可以使用window。性能?

对于那些想做和我一样的事情的人,我在MDN中找到了一个关于这个的文档:

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/encodedBodySize

方法存在,但是浏览器还没有实现。

下面是来自MDN的代码示例:
function log_sizes(perfEntry){
  // Check for support of the PerformanceEntry.*size properties and print their values
  // if supported.
  if ("decodedBodySize" in perfEntry)
    console.log("decodedBodySize = " + perfEntry.decodedBodySize);
  else
    console.log("decodedBodySize = NOT supported");
  if ("encodedBodySize" in perfEntry)
    console.log("encodedBodySize = " + perfEntry.encodedBodySize);
  else
    console.log("encodedBodySize = NOT supported");
  if ("transferSize" in perfEntry)
    console.log("transferSize = " + perfEntry.transferSize);
  else
    console.log("transferSize = NOT supported");
}
function check_PerformanceEntries() {
  // Use getEntriesByType() to just get the "resource" events
  var p = performance.getEntriesByType("resource");
  for (var i=0; i < p.length; i++) {
    log_sizes(p[i]);
  }
}