Tuesday, December 27, 2011

Javascript Error - IE Stop Running This Script



Most often web developer experiencing “stop running this script? “  error in IE browser, especially in IE7 and IE6. This script error is triggered by following causes which is not focused by programmer while handling large volume of page content (DOMs).
Causes:

  1.  Javascript looping the operation in infinite time or more than threshold. (or)
  2. Javascript read/write DOM in many times. (or)
  3.  Mulitple ajax request at the same time. (or)
  4.  Synchronous ajax. (or)
  5.  Deadlock in called function.
Sollution:
1)      Go through your code and just use try and catch inside loop. Better to define termination of loop on exception.
2)      Please limit loop with few number of iteration (Normally iteration in 100s would be better).
3)      Minimise searching object within DOM. Here jQuery developers have to focus the area selector.
A)     Avoid global Selector. [ $(“*”) ]
B)      Avoid global find operation. For example, use $(“div#myID”).find() instead of $(“body”).
C)      Minimize the Selector function call. For example use copy of selected object instead of using selector. For more clearance see following piece of code


4)      Use Asynchronous ajax by setting the property “async: true” in $.ajax({}).
5)      Threading script flow by using setTimeout() (or) setInterval(). Let’s take above code snippet. Let’s assume css() function is independent of its following line. And css() doesn’t return any value and  it’s output is not required by subsequent lines, means call css() function with setTimeout as follows,

6)      Avoid duplication of event handler. These kind of duplication is occurred existence of same code in single js file or different js files. For example doubled existing of the code following code will give two alert box for single click.

Note: Please leave your queries and suggestion as comment.

No comments:

Post a Comment