a script on this page is causing ie to run slowly

2019-01-07 07:49发布

The problem is in the title - IE is misbehaving and is saying that there is a script running slowly - FF and Chrome don't have this problem.

How can I find the problem . .there's a lot of JS on that page. Checking by hand is not a good ideea

EDIT : It's a page from a project i'm working on... but I need a tool to find the problem.

End : It turned out to be the UpdatePanel - somehow it would get "confused" and would take too long to process something. I just threw it out the window - will only use JQuery from now on :D.

And I'm selecting Remy Sharp's answere because I really didn't know about the tool and it seems pretty cool.

14条回答
爷、活的狠高调
2楼-- · 2019-01-07 08:12

For IE, the dialog is based on the # of JS commands processed. See here for info & method to change default: http://support.microsoft.com/kb/175500

查看更多
放荡不羁爱自由
3楼-- · 2019-01-07 08:13

Long running scripts are detected differently by different browsers:

  • IE will raise the warning once 5 million statements have been executed (more info on MSDN)
  • Firefox will warn if the script takes longer than 10 seconds (more info on MDN)
  • Safari will warn if the script takes longer than 5 seconds
  • Chrome (1.0) has no set limit and will simply keep trying until an OutOfMemory exception at which point it crashes
  • Opera will just continue to run forever, without warning.

Nicholas Zakas has written an excellent article covering this topic.

As such - the best way to avoid these problems is by reducing looping, recursion and DOM manipulation.

查看更多
Anthone
4楼-- · 2019-01-07 08:14

I found that adding alert('before X') alert('after X') was helpful for me to find my issue. I added them to my $(function () {

}

查看更多
Root(大扎)
5楼-- · 2019-01-07 08:14

There are few reason for this kind of alert

  1. No. of JS instructions executed by IE exceeds predefined limits. This can be fixed by editing windows registry see Here

  2. Optimize the javascript code so that execution time is reduced.

  3. JS code optimization is a real trial and error subject and there are few thumb rules to do so. Just Google it.
查看更多
Viruses.
6楼-- · 2019-01-07 08:16

If you have control over the JavaScript, you could break it into separate scripts or try a Lazy Load approach.

Just my $.02

查看更多
Explosion°爆炸
7楼-- · 2019-01-07 08:22

I don't believe there's a tool that can find the offending script. You might try attaching an IE debugger like Visual Studio and maybe it will break at the point where the problem is occurring. But I can't give any guarantees on that working.

In the past when I've had similar problems I've simply commented out sections of code to test narrow down where the issue is occurring, usually in a binary search type pattern. Comment out half of the javascript libraries, etc...

Aside from that as others have said, this type of problem occurs from large loops and many setTimeout function calls or setTimeout recursive loops.

查看更多
登录 后发表回答