使用JavaScript获取资源的传输大小 [英] Get transferred size of a resource using JavaScript

查看:256
本文介绍了使用JavaScript获取资源的传输大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试衡量真实网站用户的网页加载效果。为了更好地理解数据,我想根据缓存是否已准备好来对数据进行分段。

I'm trying to measure page load performance of real website users. To make better sense of the data, I'd like to segment the data by whether or not the cache was primed.

所以我在加载前不需要知道资源,如果它在缓存中。这足以在事后进行衡量。

So I don't need to know before loading a resource if it was in the cache. It's enough to measure after the fact.

至少在Chrome和Firefox中,开发工具网络选项卡有一列显示传输的大小。是否可以通过JavaScript获取此信息?

At least in Chrome and Firefox, the dev tools "network" tab has a column which displays the transferred size. Is it possible to get this info with JavaScript?

资源计时API似乎准备好了这种情况( transferSize 如果在本地检索资源,则必须返回0),但没有浏览器实现它

The Resource Timing API appears to have a provision for exactly this case ("transferSize must return 0 if resource retrieved locally"), but no browser has implemented it yet.

开发工具显示这些信息的事实让我想知道它是否可以以某种方式访问​​。任何想法?

The fact that the dev tools display this information makes me wonder if it's accessible somehow. Any ideas?

推荐答案

看来,虽然大多数现代浏览器,最近对Resource Timing API规范的更改,例如 transferSize 属性,尚未实施。

It appears that whilst the Resource Timing API is supported in most modern browsers, recent changes to the Resource Timing API specification, such as the transferSize property, have not yet been implemented.

以下是针对 Firefox报告此问题的相关错误 Chromium

如问题评论中所述,似乎这已在Firefox中得到解决,并将在Firefox 45中发布。我已确认 transferSize 目前可在Firefox Developer Edition(v45.0a2)中使用。

As mentioned in the comments to the question, it appears that this has been addressed in Firefox and will be released in Firefox 45. I have confirmed that transferSize is currently available in the Firefox Developer Edition (v45.0a2).

这篇关于使用JavaScript获取资源的传输大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆