最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

timeout - Maximum execution time for JavaScript - Stack Overflow

programmeradmin1浏览0评论

I know both ie and firefox have limits for javascript execution (Source 1, Source 2). Based on number of statements executed, I heard it was 5 million somewhere in IE and based on number of seconds in firefox: it's 10 seconds by default for my version.

The thing I don't get is what cases will go over these limits:

  1. I'm sure a giant loop will go over the limit for execution time

  2. But will an event hander go over the limit, if itself it's execution time is under the limit but if it occurs multiple times?

Example:

Lets say I have a timer on my page, that executes some javascript every 20 seconds. The execution time for the timer handler is 1 second. Does firefox and ie treat each call of the timer function seperatly, so it never goes over the limit, or is it that firefox/ie adds up the time of each call so after the handler finishes, so after 200 seconds on my site (with the timer called 10 times) an error occurs even though the timer handler itself is only 1 second long?

I know both ie and firefox have limits for javascript execution (Source 1, Source 2). Based on number of statements executed, I heard it was 5 million somewhere in IE and based on number of seconds in firefox: it's 10 seconds by default for my version.

The thing I don't get is what cases will go over these limits:

  1. I'm sure a giant loop will go over the limit for execution time

  2. But will an event hander go over the limit, if itself it's execution time is under the limit but if it occurs multiple times?

Example:

Lets say I have a timer on my page, that executes some javascript every 20 seconds. The execution time for the timer handler is 1 second. Does firefox and ie treat each call of the timer function seperatly, so it never goes over the limit, or is it that firefox/ie adds up the time of each call so after the handler finishes, so after 200 seconds on my site (with the timer called 10 times) an error occurs even though the timer handler itself is only 1 second long?

Share Improve this question edited Jun 16, 2010 at 3:28 Daniel Vassallo 344k72 gold badges512 silver badges446 bronze badges asked Jun 12, 2010 at 20:42 Andrew ChangAndrew Chang 1011 gold badge1 silver badge3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

The following article by Nicholas C. Zakas discusses how and when different browsers interrupt long running JavaScript code:

  • What determines that a script is long-running?

Breaking long processing code into small chunks and launching them with timers is in fact one way to get around this problem. The following Stack Overflow post suggests a method to tackle this:

  • Show javascript execution progress

On the other hand, web workers would be more suited for long running processing, since their execution happens in a separate process, and therefore does not block the UI thread:

  • Mozilla Dev Center: Using web workers
  • John Resig: Computing with JavaScript Web Workers
  • Nicholas C. Zakas: Experimenting with web workers

However web workers are not supported in Internet Explorer yet, and they would not have access to the DOM.

The event handler is considered a new execution context - the time limit is reset.

If you need to do even more putation, take a look at WebWorkers.

I too stuck in this kind of JS error. I also get the solution, unfortunately only for IE, which tells to edit the registry (regedit mand) and update the number of JS mands to allow. Read more here http://support.microsoft./?kbid=175500.

But this doesn't seems to be a good solution to me bcoz if you are developing a web application you can not ask every user to use only IE and update his system registry.

As a workaround: If your data to process at client end is really large then you can put some manual delays between fix set of events processing. For ex. If there are 100 events of any task you want to process then you can break them in to 10 sets of 100 and process each of them in say 100ms. To know how to do that follow below link:

http://www.nczonline/blog/2009/01/13/speed-up-your-javascript-part-1/

发布评论

评论列表(0)

  1. 暂无评论