It is not recommended to export large excel files for download. It's best to break the data into smaller chunks for the user to download in batches. However, if you still need to handle a big excel file download, refer to the solution below.
Consider downloading the json data in batches and combining them into a single excel file for user download!
When a script becomes unresponsive, it means a Javascript thread is taking too long to complete. Modifying the registry could be a solution, but it would need to be done on all client machines. One way to address this is by using a "recursive closure", which allows for a long-running loop to yield control to the browser intermittently, preventing the unresponsive script dialog.
To implement this, add the Utility Class RepeatingOperation to your javascript file. You can use the following code:
RepeatingOperation = function(op, yieldEveryIteration) {
var count = 0;
this.step = function() {
if (++count >= yieldEveryIteration) {
count = 0;
setTimeout(function() { op(); }, 1, [])
return;
}
op();
};
};
The problematic code causing the 'stop running this script' dialog can be fixed using the following approach:
process10000HeavyTasks = function() {
var len = 10000;
for (var i = len - 1; i >= 0; i--) {
heavytask();
}
}
Here is the solution for the problematic code:
process10000HeavyTasks = function() {
var global_i = 10000;
var repeater = new this.RepeatingOperation(function() {
heavytask();
if (--global_i >= 0){
repeater.step();
}
else {
alert("Task completed");
}
}, 10);
repeater.step();
};
Modified from the following source: