I have been changing how the javascript on my website works to make it more responsive. I have added lines like this:
setTimeout(function () {doTasks();}, 0);
Is it always enough to have a timeout of 0? Are there any browsers where this trick will not work?
Yes, this works in every browser.
But note that the actual delay will be around 10 ms.
For those who don’t understand. This will empty the call stack as the callback function will be called asynchronously. Plus it gives the program some time to “breathe” and do stuff like firing other events or updating the UI.