Fabian Vilers wrote:
I'm my script I've three loops processing a very huge data file. IE &
Firefox show a message box after some time saying my script could be
infinite looping and give me a chance to stop it.
Is there a way to prevent this dialog box to show up? I'm writing a
script used only on a intranet and the final customer should not see
the message box.
Since as you say not only using client-side scripting is not an option, I
think with unchanged code (see below) you will have to restrict your target
browser to Firefox and have your clients set this preference in their
user.js configuration file (or via `about
:config'):
user_pref("dom.max_script_run_time", "0");
Setting this preference to 0 is specified to disable the warning. I have
set it to 60 (seconds) here.
I do not know if there is such a preference for IE, hence the Firefox
restriction.
However, you should definitely analyze the efficiency of your code,
especially of your loops, before you try anything else. For example,
using
/* a is an Array or collection object */
// order does not matter
for (var i = a.length; i--;)
or
// order does matter
for (var i = 0, len = a.length; i < len; i++)
is known to be faster than
for (var i = 0; i < a.length; i++)
Storing references of lookups from to the second level upwards in a (local)
variable and reusing that variable instead of looking up over and over
again (as was done in the first two examples) is another working means to
increase runtime efficiency, thus decreasing runtime.
HTH
PointedEars