我目前正在保存一些httpCall的持续时间来分析我的Web应用程序的性能。我使用 window.performance.getEntries()并只获取我需要的电话。
所有工作都很完美,但我希望获得此保存通话的大小。这可以使用window.performance?
答案 0 :(得分:1)
对于那些想要和我做同样事情的人,我在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]);
}
}