javascript: detect browser speed and load the “slow connection” site version

How to detect the browser speed?

It’s easy, you just put a ajax or image load in the beginning of the page and than you know what the speed is. But the problem is that the ajax and the image load need to finish to know exactly how slow or fast the connections is. And even worse, you need to slow down the page even for normal (fast) connections. And where’s the point? You get the site slower only to understand the connection. That’s not OK.

The javascript blocks the page load

That’s another problem with javascript. You know when you have script tag in the head of the document, the browser needs to finish loading this javascript, parse it and than continue loading.

How javascript can be loaded async

Well there are several methods, but here we need only one separate javascript that don’t communicate with other JS code in the site, it only get information about the connection speed.

Put the javascript code in an Iframe.

Than the loading of that javascript is async. Independently you continue loading the site. For fast connection, yes this going to slow down a little bit, but however not as much as if you put an inline code. Than in that iframe you can simply check for an expression to verify for a slow connection if it’s true you may set a cookie for slow connection site version and reload the window.parent of the iframe, which is the page itself.

2 thoughts on “javascript: detect browser speed and load the “slow connection” site version

Leave a Reply

Your email address will not be published. Required fields are marked *