Is there any way to detect if a computer is slow and not run some code (by either turning jQuery animations off or just running a function if it is fast)?
I kno
When running javascript, you don't have the luxury of knowing the target computer's performance beforehand. The only thing I can think of, would be to run a function doing some calculations and measuring the time taken. The function must do a sufficient number of calculations in order to make sure that the time taken to run, is representative of the performance of the machine.
In general, I would advise against doing such a performance test, because it takes resources on the target machine, something that users generally don't like. But perhaps you could measure the time taken to complete the first animation, and if it is too slow, disable subsequent ones.
The most simple solution would be to leave it up to the user with a check box, but other wise you could try timing the first animation for a computer and then if it exceeds a certain time limit, the remaining animations are turned off... for example...
var start = new Date();
//... some jQuery animation
var end = new Date();
var diff = end - start;
Then, for example, if the animation should take 1.5 seconds, and the time difference is like 5 seconds, then turn off any remaining animations.
i think there are two options:
Let the user decide - give a 'low bandwidth/low spec' option to the user which when clicked will display the simpler version of the site.
Try to detect slow machines - you could try to detect a slow machine by using a timeout script - if the animation/loading doesn't complete within a certain time switch to the simpler version of the site. The downside to this method is that you have no idea why the script timed out - perhaps it was a bad connection or the user was loading something else at the same time temporarily slowing their machine.
Hope this gives you some ideas.
Josh
Given that JavaScript runs in a partial trust environment, you're not going to be able to get any OS-level info, I would think.
The best you can do really is test "responsiveness". A possible approach would be just to start playing the full animation and detect lag by comparing the target frame rate with "real" frame rate. You could then simply skip bits of the animation (code) to reduce the computation time and thus improve the responsiveness/frame-rate accordingly. This is essentially how many desktop games detect lag and thus reduce the complexity of animations. I can't guarantee it will work equally well in the browser with JavaScript, but it's worth a try certainly.
I'm guessing that the code which you want to switch off takes a significant amount of time to run.
I suggest that you:
I would like to point out that if you're going to leave it up to the user (which I think is a good idea) you should make it clear that you're asking about computer speed, not connection speed or bandwidth. A user may have a very fast laptop, but be working on a slow public wi-fi connection, or vice versa. Since Javascript is client-side, it's only the computer speed that matters.