如何仅使用 javascript 获取以 KB 为单位的当前页面大小?

2022-01-18 00:00:00 widget javascript html

参考这个问题 , 如何获取当前页面大小 (kb), 我将使用这个大小来了解该页面的连接速度.

Referring to this question , how can i get the current page size in kb, this size i will use to know the connection speed for this page.

推荐答案

除非你的页面大小以兆字节为单位,否则结果将毫无意义.

Unless your page has size in megabytes, the result will be meaningless.

这是因为连接、发送请求和等待服务器发送回复所需的时间是 相当大 与下载页面所需的时间相比,此外 TCP/IP 还有 慢启动.

This is because time needed to connect, send request, and wait for server to send reply back is quite large compared to time required to download the page, and in addition to that TCP/IP has slow start.

您还必须考虑缓存、代理和浏览器将建立的并行连接数(例如,可能优先下载脚本和样式,使页面下载时间显得很慢).

You also have to take into account caches, proxies and number of parallel connections that browser will make (e.g. may prioritize download of scripts and styles, making page download time appear slow).

相关文章