admin管理员组文章数量:1391951
I have a javascript LONG execution procedure (and reasons to have it). How can I avoid in javascript the message on the client machines? I read something about --disable-hang-monitor, but is a mand line argument or setting, not javascript (also, I read isnt working allways)
I have a javascript LONG execution procedure (and reasons to have it). How can I avoid in javascript the message on the client machines? I read something about --disable-hang-monitor, but is a mand line argument or setting, not javascript (also, I read isnt working allways)
Share Improve this question asked Mar 8, 2019 at 21:52 gtryonpgtryonp 4075 silver badges13 bronze badges 4-
Do
async
anddefer
attributes on script tags solve the problem? – Ali Sheikhpour Commented Mar 8, 2019 at 21:58 - In most cases there should be no valid reasons to have such scripts. You say that you have "reasons", what are they? What is the code doing? – battlmonstr Commented Mar 8, 2019 at 22:07
- Thanks Ali Sheikhpour for your ment. but neither async nor defer avoid the message when the scripts takes a long time. – gtryonp Commented Mar 10, 2019 at 6:23
- Thanks battlmonstr for your ment. (In short: A project to create software capable to write code business logic by itself), But please focus in help us -if you know how- with the question. – gtryonp Commented Mar 10, 2019 at 6:44
1 Answer
Reset to default 5Assuming you are doing plex calculations that can't be broken down in smaller chunks, web workers seem to the solution to me. It's the javascript mechanism to run code in a separate thread, but you have to municate with that thread (called a worker) via messaging: https://developer.mozilla/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
var myWorker = new Worker('worker.js');
first.onchange = function() {
myWorker.postMessage([first.value,second.value]);
console.log('Message posted to worker');
}
second.onchange = function() {
myWorker.postMessage([first.value,second.value]);
console.log('Message posted to worker');
}
myWorker.onmessage = function(e) {
result.textContent = e.data;
console.log('Message received from worker');
}
In the worker:
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
console.log('Posting message back to main script');
postMessage(workerResult);
}
本文标签: Avoid chrome quotpages unresponsivequot upon javascript long executionStack Overflow
版权声明:本文标题:Avoid chrome "pages unresponsive" upon javascript long execution - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744756760a2623509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论