a script on this page is causing ie to run slowly

前端 未结 14 2365
野性不改
野性不改 2020-11-29 23:55

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 prob

相关标签:
14条回答
  • 2020-11-30 00:24

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

    Just my $.02

    0 讨论(0)
  • 2020-11-30 00:25

    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.
    0 讨论(0)
  • 2020-11-30 00:27

    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.

    0 讨论(0)
  • 2020-11-30 00:28

    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.

    0 讨论(0)
  • 2020-11-30 00:29

    If javascript ties up page processing for more than 10 seconds, you get this message. IE obviously has a slower javascript engine, causing this.

    I'm guessing that some code optimization will certainly help, and try reducing the amount of javascript executing on page load. Perhaps use setTimeout() to defer processing of some unnecessary things if you have to.

    As far as tools go, use Firebug's profiler to see where you're spending so much time.

    0 讨论(0)
  • 2020-11-30 00:31

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

    }

    0 讨论(0)
提交回复
热议问题