如何使用 JavaScript 近似计算网站的连接速度?
如何使用 JavaScript 近似计算网站的连接速度?
How to calculate approximately the connection speed of a website using JavaScript?
我想创建一个类似的 javascript 小部件,它将计算打开当前打开页面的速度.
I want to create a javascript widget like, which will calculate the speed opening the current opened page.
我在问这是否可以仅使用 javascript 来完成,想法是什么.
I am asking if this can be done using just javascript and what will be the idea.
更新
请注意,页面大小始终为未知.
Note that the page size is always Unknown.
推荐答案
这里是一个使用 AJAX 和 .Net 后端的示例,尽管它可以是任何东西.
Here's an example using AJAX with .Net backend, though it could be anything.
这里是一个使用图片的简单示例.
Here's a simpler example using an image.
关键是要有一个已知大小的页面/对象,并在浏览器检索它时捕获开始和结束时间.然后只需将大小除以某个 [时间单位] 即可得到每个 [时间单位] 的 [大小].然后用数学把它翻译成你想要的.
The key is to have a page/object of a known size and capture the start and end times as the browser retrieves it. Then simply divide the size by some [unit of time] to get [size] per [unit of time]. Then use math to translate this into whatever you want.
相关文章