1

I have an inherently complicated page designed by an idot running a script on load that takes too much time and generates the Stop Script dialog box.

The page works fine on all tested browsers except IE6/7/8.

I would like to know if I can break up the script with settimeouts to avoid this error.

Something like: $('.level').each(f(){settimeout(f(){script},1)});

Update: Yes of course I knew everyone would want to see code, but it's big too. Perhaps this line will indicate the idea of what's happening at the top level of the onload:

    $('#thetable').find('tr.listing :checkbox').click(function(event) { ... });

where there are around 5700 dom nodes in #thetable in one of the more modest sets of search results.

3
  • 3
    Yes you could. But without seeing some code, or even an overview of what it's doing we can't give you a definitive answer on wether this is the best method of improving performance of the script. Commented Mar 23, 2012 at 13:37
  • Perhaps you might be better off by refactoring the script ... Commented Mar 23, 2012 at 13:54
  • @Christoph, yes and my thought was to break up the binding of onclick events to a whole lot of tags by means of settimeout, any other refactoring ideas? Commented Mar 23, 2012 at 14:19

1 Answer 1

1

I think the search on this selector $('#thetable').find('tr.listing :checkbox') is what is taking the time in IE.

There are a couple things you could do...

It sounds like your showing a result set in a table. In this case you may want to implement paging and have the script go back to the server for more results on the page change event. This will mean less DOM nodes to process, and should take care of the stop script problem.

Another approach you could try is giving your check boxes predictable ID's and then doing a direct select such as $("#thetable_checkbox_" + checkboxid) and then having a forloop iterate through the results, changing the checkboxid you are selecting on.

Here is some pseudocode as an example

for (int x = 0; x < numResults; x++) {
    setTimeout(function() {
        $("#thetable_checkbox_" + x).bind(function() {
             clickEventFunction()
        });
     }, 0);
 }

Where your checkbox ID's have been generated on with ID's like thetable_checkbox_1 etc.

The approach you mentioned for breaking up the script with setTimeout will also work, but you need to avoid jQuery selectors that could take a long time. You can also set the timeout value to 0 since you want it to run as soon as the browser is ready. Setting the timeout to 0 yeilds to the browser and allows it to run any operations it has pending before returning to your script. If the script is long running you should display a modal loading dialog so that the page is only displayed to the user when it is ready.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, for the freedom to do it right. Marketing has already set (in fact the site is live behind a subscription or I'd share it with you) the nature of the results gird and the idea of paging it was out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.