I fear I already know the answer, but I might as well risk it: Does anyone know if there is some way I can test whether a client that is accessing a website is a thin client (desktop terminal) or not? The issue here is that thin client start to lag horribly if you even consider using JavaScript(animation).
I basically want to serve a "light" version of the website, where I disable all special effects depending on the client. I have looked at the user agent but that doesn't seem to give away anything useful.
Is there any way to tell?
There's no really clean way to solve this, because there's no such thing as a HTTP header for thin clients or remote desktops.
But if you really need a solution to identify slow clients, you can try the following. It's similar to what Google uses on Maps to determine if a client can handle Maps.
In this approach, you would deliver the HTML page with a chunk of embedded JavaScript. This chunk performs a resource-heavy operation which should be similar to what your actual code does.
You measure the time consumed for this operation and decide if it's performing well or not.
Now you load the actual JavaScript, either by creating the script tag with document.write
and passing a parameter which tells the script in which mode to run, or by initializing the already loaded code with an appropriate parameter.
A quick'n'dirty example implementation would look like this (using jQuery, but can as well be implemented in plain JS):
<script type="text/javascript">
var
$elem,
now = new Date(),
isFast,
counter = 0;
while (new Date() - now < 100)
{
$elem = $('<div style="display: none">');
$('body').append($elem);
$elem.remove();
++counter;
}
alert(counter);
isFast = (counter > 100);
// now, either embed the actual script ...
document.write('<scr'+'ipt type="text/javascript" src="http://www.example.com/js/test.js?fast=' + isFast + '"></scr'+'ipt>');
// ... or initialize the already loaded code
var myControllerInstance = new MyController(isFast);
myControllerInstance.makeStuffHappen();
</script>
The delicate part is to define what is “fast”, because there may be different reasons why the timing code runs slow. You could end up with too many false negatives or false positives.
EDIT: Updated JS example, as proposed by @fero. Thanks!