I’d like to make a js watch that:
- Start time is server time (the server will supply that in the page’s source code).
- Updates every second.
- (preference, not obligatory) Compatible with the latest versions of gecko, webkit, presto and IE.
I have already checked many implementations of this but I wanted to know which one is the most efficient one. That is: the one that takes less resources from the PC and the one that is more precise among all the ones that exist.
A clock that ticks every second is basically animation, so one could benefit from recursive
requestAnimationFrame(with fallback tosetTimeout).With
setIntervalyou’d have to create aDateobject on each iteration, becausesetInterval‘s own delay may take longer than it’s formal value. See John Resig’s brilliant article on timers in JavaScript.requestAnimationFrameon the contrary is: