Wednesday, May 30, 2007

Why doesn't javascript has a sleep/wait function

One of the primary goals of affective web designing is increasing web page responsiveness and that is the goal which lead to the development of Javascript and then Ajax. What i really couldn't understand is, why doesn't javascript has an inbuilt sleep/wait functionality? A user might ask, why do we need such a function? The reason is that when you execute a script which does a lot of work, taking lot of time the browser just becomes unresponsive on slow computers. Executing such scripts in smaller steps would have been much for usefull. As a test just go to slashdot and go to any story with more then 250 comments. Try reducing the expanded comments to 0 and then increasing them to the maximum allowable limit. A user will not be seeing all the +250 comments at the same time and thus executing the script at small intervals would have been much more effective. Granted javascript provides the setTimout function which can be used to rewrite the function to do the work properly. but, is this the correct way? Having a native sleep/wait function would have been much nicer.