使用javascript的带宽实用程序 [英] Bandwidth utility using javascript

查看:148
本文介绍了使用javascript的带宽实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何实用程序来测量从我的服务器到客户端或任何标准APIS的带宽。需要这个用于Web应用程序

IS there any utility to measure bandwidth from my server to the client or any standard APIS.Need this for web application

推荐答案

不知道任何实用程序或标准API,不,但您可以通过在您的网站上放置多个不同大小的图像,然后绕过缓存检索它们并观察它们加载所需的时间来实现。该信息以及图像的大小为您提供了两个端点之间速度的指示

Don't know of any utility or standard API, no, but you can do this by having several images of various sizes on your website, and then retrieving them bypassing cache and watching how long it takes for them to load. That information, along with the size of the image, gives you an indication of the speed between the two endpoints.

使用多个端点的原因图像是你想要从小开始(例如,20k),但如果连接速度很快,会给你一个非常不准确的数字;因此,根据加载图像的速度,您需要选择适当大小的其他图像,以便更好地了解实际带宽(而不是设置连接的等待时间等)。

The reason for using multiple images is that you'll want to start small (say, 20k), but if the connection is fast that will give you a very inaccurate number; so based on how quickly that image loaded, you'll want to select another image of an appropriate size to try to get a better idea of the actual bandwidth (as opposed to the latency setting up the connection and such).

您只需使用直接JavaScript即可,只需在页外添加 img 标记,并使用唯一的查询字符串来绕过缓存;但是当你标记了你的问题jQuery时,你可能会发现使用 .ajax函数更方便(使用缓存:false 设置)代替。

You can do this just with straight JavaScript, by adding img tags off-page with a unique query string to bypass caching; but as you've tagged your question "jQuery", you may find it more convenient to use the .ajax function (with its cache: false setting) instead.

您提出的速度数字是只是一个指示,因为其他事情可能正在搞乱你的时间(在另一个标签中的视频流—或者在连接到同一个互联网连接的另一台计算机上,甚至其他东西会减慢JavaScript的执行速度,比如JS - 页面上的重要动画),但它应该足以让你知道你正在使用的是什么。

The speed number you come up with is only an indication, since other things could be going on that mess up your timing (video streaming in another tab — or on another computer hooked to the same internet connection, even other things slowing up the execution of your JavaScript, like a JS-heavy animation on the page), but it should be good enough to give you an idea what you're working with.

这篇关于使用javascript的带宽实用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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