Last active
December 14, 2015 22:48
-
-
Save basecode/5160894 to your computer and use it in GitHub Desktop.
A simple example of spawning an inline worker using Blob API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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