0

I was wondering how I could isolate the execution of a JavaScript function to avoid the browser to break.

Example: if I want to output in console an associative array with around 10k elements, the browser would stop responding. How can I avoid that?

2
  • So you want to run the code asynchronously? Commented Mar 15, 2017 at 13:56
  • Since Javascript is known to run in single thread, I hardly think it's possible. Commented Mar 15, 2017 at 13:56

1 Answer 1

2

The solution is a Web Worker.

A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.

Source: https://www.w3schools.com/html/html5_webworkers.asp

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

Comments

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.