Re:Show HN: Cross-browser asynchronous JS script loader w/ca...
by phoboslab on Tuesday September 04, 2012 @04:19AM
(#4473644)
How has setTimeout "much better performance" than setInterval? It's a myth that setInterval queues up function calls if they take a long time, if that's what you're referring to.
Re:Show HN: Cross-browser asynchronous JS script loader w/ca...
by anatoli on Tuesday September 04, 2012 @09:33AM
(#4474447)
"Much better performance" is perhaps a bit misleading since it's not black and white, but at the core OP is right. See this thorough SO answer for more info: http://stackoverflow.com/a/731625/886402
Specifically:
1) the window.onload is being directly overwritten without any chaining. The safe way is to first store a reference to whatever was in .onload beforehand and call that in the overwritten onload.
2) the load check uses an interval on a 10ms timer. Chained setTimeouts are much better for performance and 10ms is quite an aggressive default. 50ms gets called 5x fewer and has a imperceptible difference to the user.
3) _async is some big ol' global var with no function scoping at all.