How to handle "a script on this page causes Internet Explorer to run slowly"?

From javascript, I call the web method. With IE, if I pass a huge parameter to this web method, the warning “Stop stopping this sciprt? A script on this page causes Internet Explorer to run slowly”.

Is it possible to process a click on the “Yes” button, so if the user decides to cancel the script, I can run an alternative script (in this case, my “alternative” script is to close some progress bar that I run before the script runs for a long time).

I saw a lot of messages explaining how to prevent this warning from appearing, but I do not want the warning not to be displayed: I just want to be able to handle the case when the user decides to stop script execution.

+7
source share
1 answer

I looked at this before in the internal application, where they didn’t care how long it took for the browser to crack the numbers, they just didn’t want them to click the hint.

The key is to break the work into relatively predictable pieces of work (predictable in terms of CPU time) and run them on setInterval, for example:

function doWork(begin, end) { // Some chunk of what your worker function normally does from begin to end if (actualEnd < end) // Nothing left to do clearInterval(Interval); } var Interval = setInterval(doWork, 15); 

This prevents the IE prompt from appearing (or Chrome presents the Freeze dialog box). The next step is to add code that allows the user to completely skip it; if the number of jobs is known at the beginning, ask them right away. If not, start processing and after n pieces ask them if they want to make a cheaper function.

There are 2 more options for doing this job:

  • See how much work needs to be done, and if it is a lot, pass it to the server (this, unfortunately, means reusing JS on the server, of course, you can use the server engine that runs Javascript to save some coding).
  • Use background workers from Google Gears / HTML5

Finally, if you do this work on demand, there may be acceleration opportunities in the work you do - the data can be indexed in advance on the server to make the calculations faster / easier, something like this, but I don’t know what you count.

+4
source

All Articles