views:

544

answers:

4

I am working on a ASP.NET webpage that is rather complex with ajax, callbacks, javascript etc. I encounter this error intermittently:

Stop running this script? A script on this page is causing IE to run slowly...

Any help in finding the culprit is really appreciated.

+3  A: 

This could happen if you have an infinite loop or a synchronous ajax call that is not returning. I would recommend you use either Firefox with Firebug, Fiddler, or the IE development tool to debug the problem.

Jose Basilio
+1 for Firebug... I don't know how I got on without it!
Dave Swersky
+2  A: 

Some of the following is helpful when trying to debug javascript:

  • Install firebug - it has the ability to profile your application, which can lead you to where the slowdown may be occuring in your script
  • When in doubt, use alert statements. Pepper them in your code and use them to find out where your javascript is slow.
  • Take a look at this SO question to get more javascript debugging tips, or this question on how to debug javascript in IE
  • Wrap your AJAX calls in try/catch blocks - the article Debugging AJAX in Production, describes the technique
Gavin Miller
+1  A: 

I've found a main cause for this to popup in IE vs any other browser is string manipulation. If you are concatenating strings a lot, IE performance takes a huge hit as the string grows.

But as many suggested, using a development tool will hopefully lead you to the problem area and we can help from there if needed.

Jab
+2  A: 

I would suggest reading the following article:

http://www.julienlecomte.net/blog/2007/10/28/

In a nutshell, the error message you describe happens when code executed from a single javascript entry point runs for a long time. If you can split up your long processing into pieces and call them sequentially using setTimeout(), you will no longer get the error message.

From the article, a good template for long-running javascript routines:

function doSomething (callbackFn [, additional arguments]) {
    // Initialize a few things here...
    (function () {
        // Do a little bit of work here...
        if (termination condition) {
            // We are done
            callbackFn();
        } else {
            // Process next chunk
            setTimeout(arguments.callee, 0);
        }
    })();
}
Matt Bridges