
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Why HTML5 Web Workers are useful?
JavaScript was designed to run in a single-threaded environment, meaning multiple scripts cannot run at the same time. Consider a situation where you need to handle UI events, query and process large amounts of API data, and manipulate the DOM.
JavaScript will hang your browser in situation where CPU utilization is high. Let us take a simple example where Javascript goes through a big loop:
<!DOCTYPE HTML> <html> <head> <title>Big for loop</title> <script> function bigLoop(){ for (var i = 0; i <= 10000; i += 1){ var j = i; } alert("Completed " + j + "iterations" ); } function sayHello(){ alert("Hello sir...." ); } </script> </head> <body> <input type = "button" onclick = "bigLoop();" value = "Big Loop" /> <input type = "button" onclick = "sayHello();" value = "Say Hello" /> </body> </html>
On clicking the “Big Loop” button, the following is visible:
The situation explained above can be handled using Web Workers who will do all the computationally expensive tasks without interrupting the user interface and typically run on separate threads.
- Related Articles
- Stop Web Workers in HTML5
- How can I use Web Workers in HTML5?
- How to handle errors in HTML5 Web Workers?
- Log error to console with Web Workers in HTML5
- Why are plants so useful?
- Explain why, wheels are so useful.
- What are important server response headers that are useful in web programming?
- Html5 responsiveness of the web
- Why water is useful?
- Give examples of Synthetic Fibre and why they are useful?
- What is meant by HTML5 Web Messaging?
- How to check web browser support in HTML5
- Why is wavelet transformation useful for clustering?
- Use of Ionic as desktop web application with HTML5
- Using HTML5 Server-Sent Events in a web application

Advertisements