Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created September 9, 2014 17:26
Show Gist options
  • Save roman01la/e7a7b879698574c45ca0 to your computer and use it in GitHub Desktop.
Save roman01la/e7a7b879698574c45ca0 to your computer and use it in GitHub Desktop.
Cross-origin solution for loading WebWorker
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
var workerSrcBlob, workerBlobURL;
workerSrcBlob = new Blob([xhr.responseText], { type: 'text/javascript' });
workerBlobURL = window.URL.createObjectURL(workerSrcBlob);
var worker = new Worker(workerBlobURL);
}
};
xhr.send();
@tienn2t
Copy link

tienn2t commented Mar 21, 2017

i think your webworker only process data response from ajax, not execute call ajax in background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment