Currently i have the following code:
This is within my HTML document.
<script language="JavaScript" type="text/javascript" src="workerTest.js"></script>
Now from my understanding and research a worker must be from an external file.
So within my workerTest.js i have
var iWorker = new Worker('workerTest.js');
I would prefer to declare all my works and there code within my workerTest.js and be able to create them line about i would from an external file.
So something like
var iWorker2 = new Worker('scripttagid');
Obviously the above code is wrong but i hope it illustrates my point.
Is this possible? If it is could someone point me in the right direction? Possibly some example code?
If this isn’t possible what’s the best way to do it to avoid lots of worker files. As there will be a lot of works.
Well, kind of:
Javascript:
Please note that you don’t need the element either, it’s just that storing code in strings like
'while(true){}'is hard to maintain.Demo: http://jsfiddle.net/pmSSf/ (Processor usage will spike but you can use the page since it doesn’t run in the UI thread)