admin管理员组文章数量:1318569
How to calculate approximately the connection speed of a website using JavaScript?
I want to create a javascript widget like, which will calculate the speed opening the current opened page.
I am asking if this can be done using just javascript and what will be the idea.
Update
Note that the page size is always Unknown.
How to calculate approximately the connection speed of a website using JavaScript?
I want to create a javascript widget like, which will calculate the speed opening the current opened page.
I am asking if this can be done using just javascript and what will be the idea.
Update
Note that the page size is always Unknown.
Share Improve this question edited May 20, 2009 at 19:57 Amr Elgarhy asked May 20, 2009 at 17:51 Amr ElgarhyAmr Elgarhy 69.1k70 gold badges192 silver badges310 bronze badges2 Answers
Reset to default 11Here'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.
Sure.
<script>
startTime = Date.now();
window.onload = function(){
endTime = Date.now();
//Time in ms between opening page, and loading all the date
alert(endTime - startTime)
};
</script>
Now to approximate speed. Statically you know let's say page is 200kb.
var kbps = 200 / (endTime - startTime * 1000);
本文标签: How to calculate approximately the connection speed of a website using JavaScriptStack Overflow
版权声明:本文标题:How to calculate approximately the connection speed of a website using JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742047737a2417887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论