---
title: "Explain, How to perform heavy task in the background using HTML5 and JavaScript?"  
description: "Explain, How to perform heavy task in the background using HTML5 and JavaScript?"  
author: "Gurmeet Kaur"  
published: 2018-11-17  
canonical: https://answers.mindstick.com/qa/51735/explain-how-to-perform-heavy-task-in-the-background-using-html5-and-javascript  
category: "programming"  
tags: ["html5", "javascript"]  
reading_time: 1 minute  

---

# Explain, How to perform heavy task in the background using HTML5 and JavaScript?

[Explain](https://yourviews.mindstick.com/view/86025/content-created-for-humans-not-for-bots-explain-this-statement), how to perform heavy [task](https://www.mindstick.com/news/2470/bank-of-israel-wants-to-manage-stable-crypto-assets) in the [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) using [HTML5](https://www.mindstick.com/articles/1535/offline-add-edit-delete-data-in-html5-indexeddb) and [JavaScript](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript)?

## Answers

### Answer by Arti Mishra

**"Using WebWorker API"** \

**HTML5 provides WebWorker API to perform JS operation on the background** so that **we can reduce the CPU time** **and work** because **some time JS create a web page as responsive due to the huge amount of work performed by CPU.** \

In HTML **"Worker" class is defined** to perform JS operation on the background.

![Explain, How to perform heavy task in the background using HTML5 and JavaScript?](https://answers.mindstick.com/questionanswer/33e9db25-2cbe-4077-9626-fc64161dd783/images/b808bb5a-2f16-413e-be6b-da49d62af8f9.png)\

.

**Here is a simple example for performing the heavy task in the background.**

```
 <html> <head>
 <script>
 var w=null;
 function callWorker()
 {
 if(Worker)
 {
 w=new Worker("demo.js");
 w.onmessage=function(event)
 {
 document.getElementById("res").innerHTML=event.data;
 };
 }
 else
 document.write("Worker Not Supported.........");
 }

 function stopWorker()
 {
 if(Worker)
 {
 w.terminate();
 w=null;

 }

 }
 </script>
 </head>
 <body onLoad="callWorker();">
 <h1>Welcome User........</h1>
 <h1><div align="center"id="res"></div></h1>
 <input type="button" value="Start Worker"onClick="callWorker();">
 <input type="button" value="Stop Worker"onClick="stopWorker();">
 </body>
 </html>
```

## Demo.js

```
var i=1;
function count()
{
 i=i+1;
 postMessage(i);
 alert("Hello....");
 setTimeout("count()",500);
}
count();
```

\

\

\

## "Thanks!!! for Reading"


---

Original Source: https://answers.mindstick.com/qa/51735/explain-how-to-perform-heavy-task-in-the-background-using-html5-and-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
