Download Absolute URL Website

Is it possible to load a web user script from an absolute URL? - The answer is missing.

However, there is a hack I found for this:

var worker; //= new Worker('http://xyz/FSWorker.js'); var xhr = new XMLHttpRequest(); xhr.open("GET", 'http://xyz/FSWorker.js'); xhr.responseType = 'blob'; xhr.onload = function(e) { var blob = this.response; worker = new Worker(window.URL.createObjectURL(blob)); fs_ready(); // do more stuff here }; xhr.send(null); 

I do not like this method, so I should start using the worker only when the XHR is finished. Another option is to work with the built-in worker, but this is even more ugly, because then I will have to put all my code in one huge line.

Is there a better way to do this?

+4
source share
1 answer

You have discovered a clever feature of Web Workers - you can create from almost any arbitrary text blob.

If you load the script as a <script> node on the current page, you can use a similar Blob method to create a web worker from it. As for loading remote scripts, your relying on XHR is as wide as accessing the text content of the remote script.

+2
source

All Articles