如何检测慢速互联网连接? [英] How to detect slow internet connections?

查看:165
本文介绍了如何检测慢速互联网连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,大多数热门网站,如google,yahoo检测用户连接速度是否较慢,然后选择加载网站的基本版本而不是高端版本。

Currently, most of the popular websites, like google, yahoo detect if the user connection speed is slow and then give a option to load basic version of the website instead of the high end one.

检测慢速互联网连接的方法有哪些?

What are the methods available to detect slow internet connections?

PS我认为这是通过javascript实现的,所以我会将其标记为javascript问题?但是,我正在寻找更多针对PHP的答案,如果这也与服务器有关。

推荐答案

你可以中的内联脚本块中启动超时< head> ,一旦遇到就会立即运行。然后,当加载时,您将取消超时 code>事件触发。如果超时发生,则页面加载缓慢。例如:

You can start a timeout in an inline script block in <head>, which will be run as soon as it's encountered. You would then cancel the timeout when the load event fires. If the timeout ever fires, the page is loading slowly. For example:

<script type="text/javascript">
    var slowLoad = window.setTimeout( function() {
        alert( "the page is taking its sweet time loading" );
    }, 10 );

    window.addEventListener( 'load', function() {
        window.clearTimeout( slowLoad );
    }, false );
</script>

显然,您希望将警报替换为更有用的警报。另请注意,该示例使用W3C / Netscape事件API,因此在版本9之前无法在Internet Explorer中运行。

Obviously you would want to replace the alert with something a little more useful. Also note that the example uses the W3C/Netscape event API and thus won't work in Internet Explorer before version 9.

这篇关于如何检测慢速互联网连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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