Just create a .js file where put java code. Thus create HTML Web Worker File.
Then, use it
Example: <script async src="/script.js"></script>
See Following example
Example:SCRIPT.JS
var i = 0;
function timedCount() {
i = i + 1;
postMessage(i);
setTimeout("timedCount()",500);
}
timedCount();