Profiling long running javascript in IE
I have a page with javascript that IE determines is unresponsive. Firefox works fine on this same page. How should I go about debugging this issue? I wasn't sure if Firebug's profiler would be accurate in assessing the 开发者_开发问答issue?
IE8 also has a debugger you can use; just press F12 and start stepping through it. You can also add logging statements with console.log
which you can see IE's console output. Once you find the JS that is long running, you can break it up with setTimeout
calls.
This KB article explains how the long running script timer works: http://support.microsoft.com/kb/175500
Internet Explorer now tracks the total number of executed script statements and resets the value each time that a new script execution is started, such as from a timeout or from an event handler, for the current page with the script engine. Internet Explorer displays a "long-running script" dialog box when that value is over a threshold amount. Internet Explorer doesn’t check on each instruction to see if it is over the limit. Periodically the script engine polls Internet Explorer with the number of statements executed and Internet Explorer checks if that is over the limit.
Note that the fix described in the article is simply specific to your local machine and will not fix your code for other users (that is, it tells you how to change your registry setting to lengthen the timer... this is not useful for you).
Try using this free tool for profiling JavaScript in IE: http://ajax.dynatrace.com/ajax/en/
It was reviewed by John Resig: http://ejohn.org/blog/deep-tracing-of-internet-explorer/
It has overwhelming set of features. I wish Firebug was so detailed.
If you are using IE, then you can use the built-in profiler. Hit F12 to open the Developer Toolbar, and on the Script tab, there is a button that allows you to profile just like in Firebug. You can also click on the Start Debugging button to step through your code and find where the errors are occurring.
精彩评论