3 ms·
For anybody looking to build a real clock, please don't use `setInterval`. Instead, use `requestAnimationFrame` which will avoid awkward stutters and delays. Wi
by wakamoleguy 4y ago
For anybody looking to build a real clock, please don't use `setInterval`. Instead, use `requestAnimationFrame` which will avoid awkward stutters and delays. With a second-by-second timer, `setInterval` routinely results in seconds that appear too short or too long (in this case, up to the interval time of 100ms).
Also, it's nice to see that this simple page isn't using any framework. One quick performance win is to cache the `querySelector` calls. Those will be the slowest part of the computation, and the nodes themselves never change.
- duxup 4y ago> `setInterval` routinely results in seconds that appear too short or too long I just ran into this/ noticed it on something I rebuilt, both using setInterval. It was fine before… but the new setInterval is … “off” visually. TY