Tuesday, January 6th, 2009

What Causes the Long-Running Script Warning?

Category: Browsers, JavaScript, Performance

Nicholas Zakas decided to dive deep on everyone’s favorite sign that you’ve done something wrong:

Few web developers truly understand what triggers the long-running script dialog in various browsers, including myself. So I decided to sit down and figure out under what circumstances you’ll see this dialog. There are basically two different ways of determining that a script is long-running. First is by tracking how many statements have been executed and second is by timing how long the script takes to execute. Not surprisingly, the approach each browser takes is slightly different.

He finds that Internet Explorer’s warning is based on total statements executed (5 million, and since it’s Windows, you can change it via the Registry), Firefox and Safari time the actual script time (10 and 5 seconds, respectively), Chrome is a bit of a mystery, and Opera doesn’t appear to have such a mechanism (and interestingly, appears to put its UI on a different thread than page rendering / script execution).

Regardless of the details, the lesson remains the same (again quoting from Nicholas’ post):

Brendan Eich, creator of JavaScript, is quoted as saying, “[JavaScript] that executes in whole seconds is probably doing something wrong…” My personal threshold is actually much smaller: no script should take longer than 100ms to execute on any browser at any time. If it takes any longer than that, the processing must be split up into smaller chunks.

An interesting read!

Posted by Ben Galbraith at 10:33 am
1 Comment

4.3 rating from 27 votes

1 Comment »

Comments feed TrackBack URI

Great read! I thought Nicholas last paragraph was a gem of usefulness!

Comment by skypoet — January 6, 2009

Leave a comment

You must be logged in to post a comment.