How to prevent "A script on this page makes Internet Explorer run slowly" without changing the MaxScriptStatements in the registry?

We use Bing and / or Google javascript controls, sometimes with lots of dynamically changing overlays.

I read http://support.microsoft.com/kb/175500/en-us and know how to set the MaxScriptStatments registry key.

The problem is that we do not want to programmatically install this or any other registry key on users' computers, but would prefer to achieve the same effect in some other way.

Is there another way?

+3
source share
2 answers

It is unlikely that you can do anything other than create a lighter script. Try to look at it and find out where the heaviest crunch occurs, and then try to optimize these parts, break them into smaller components, call the next component with a timeout after the previous one is completed, and so on. In principle, give control to the browser from time to time, do not digest everything in one function call.

+5
source

Typically, a long run script occurs in a loop, which is a loop.

If you need to focus on a large dataset, and this can be done asynchronously - similar to another thread, then move the processing to the web worker ( http://www.w3schools.com/HTML/html5_webworkers.asp ).

If you cannot or do not want to use a web executor, you can find your main loop that calls the long script, and you can give it the maximum number of loops, and then make it return to the client using setTimeout.

Bad: (thingToProcess may be too large, resulting in a long running script)

function Process(thingToProcess){ var i; for(i=0; i < thingToProcess.length; i++){ //process here } } 

Good: (only allows 100 iterations before returning)

 function Process(thingToProcess, start){ var i; if(!start) start = 0; for(i=start; i < thingToProcess.length && i - start < 100; i++){ //process here } if(i < thingToProcess.length) //still more to process setTimeout(function(){Process(thingToProcess, i);}, 0); } 

Both can be called in the same way:

 Process(myCollectionToProcess); 
+1
source

Source: https://habr.com/ru/post/910709/


All Articles