<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<h2>Check out the console - the worker's <code>onmessage</code> function will only be called for the second message.</h2>
</body>
</html>
console.log('[main script] initializing worker');
var worker = new Worker('worker.js');
console.log('[main script] sending first message');
worker.postMessage('hello!');
setTimeout(function() {
console.log('[main script] sending second message');
worker.postMessage('second message');
}, 0);
/* Styles go here */
console.log('[worker] starting');
setTimeout(function() {
console.log('[worker] assigning `onmessage`');
onmessage = function(mesg) {
console.log('[worker] received message: "' + mesg.data + '"');
}
}, 0);