javascript webworkers without external file
category: code [glöplog]
anyone knows if it's possible to have javascript webworkers without external file? for size optimization would be nice to keep it all just 1 file. haven't done any proper research on this, couple quick searches on google says it's not possible. anyone knows any potential work arounds?
Shot in the dark, but maybe if you put your code into a data-url it counts as external file?
new worker('data:text/javascript,....');
;)
Quote:
-- Source: TFMThus, scripts must either be external files with the same scheme, host, and port as the original page, or data: URLs. For example, you can't load a script from a javascript: URL, and an https: page couldn't start workers using scripts with http: URLs.
;)
haha :D
<3
<3
Of course you can have the worker code in your main JS, get the string version of the methods you want in the worker, btoa the whole thing and feed it to the data:URL to instantiate the worker.
HTH,
HTH,
awesome
I read
Quote:
javascript webworkers without external life
Me too.
germany is making you dyslexic ;)
Have you ever been to the engineering level?
Oh, never mind.
Oh, never mind.
Code:
Function.prototype.workerify = function(){
var b = this+"";
return window.URL.createObjectURL(new Blob([b.slice(b.indexOf("{")+1,b.lastIndexOf("}"))],{type:"text/javascript"}))
}
Instead of &q uot; there must be just a ".
Okay, this was overkill. This should work too (pass the function as a parameter).
Code:
workerify=function(f){return URL.createObjectURL(new Blob([(f+"").trim().match(/{(.*)}/)[1]]))}
Hm. even trim isn't necessary.
> haven't done any proper research on this, couple quick searches on google says it's not possible.
With modern Web tech, everything is possible.
Code:
workerify=function(f){return URL.createObjectURL(new Blob([(f+"").match(/{(.*)}/)[1]]))}
> haven't done any proper research on this, couple quick searches on google says it's not possible.
With modern Web tech, everything is possible.