Skip to content

Instantly share code, notes, and snippets.

@basecode
Last active December 14, 2015 22:48
Show Gist options
  • Save basecode/5160894 to your computer and use it in GitHub Desktop.
Save basecode/5160894 to your computer and use it in GitHub Desktop.
A simple example of spawning an inline worker using Blob API.
<html>
<body>
<script id="worker" type="text/worker">
onmessage = function(e) { postMessage('worker: ' + e.data); }
</script>
<script type="text/ecmascript">
var blob = new Blob([
document.querySelector('#worker').textContent
]);
var blobURL = window.URL.createObjectURL(blob);
var worker = new Worker(blobURL);
worker.onmessage = function(e) {
console.log(e.data);
};
worker.postMessage('ui-thread');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment