Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  87] [ 4]  / answers: 1 / hits: 47321  / 13 Years ago, tue, august 9, 2011, 12:00:00

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?



P.S. I think this is achieved through javascript, so I will tag it as a javascript question? However, I am looking for answers oriented more towards PHP, if this is also server related.


More From » javascript

 Answers
30

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>


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.


[#90720] Monday, August 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
1 Year ago
;