I have created a shopify app that uses the graphql api and gets data.
I want to set up the fetch on another thread and want to use a web worker I have created the worker.js in the assets folder but the domain of this file is on the https://cdn.shopify.com and not https://mystore.myshopify.com/ domain and the worker wont work as I get the error "cannot be accessed from origin"
Here is the worker I am using to test getting data
var worker;
testWorker();
function testWorker()
{
if (typeof(Worker) !== "undefined")
{
if (typeof(worker) == "undefined")
{
worker = new Worker("{{ 'webworkertest.js'| asset_url }}");
}
worker.onmessage = function(event)
{
document.getElementById("loopcount").innerHTML = event.data;
}
}
else
{
document.getElementById("loopcount").innerHTML = "Web Worker not supported";
}
}
function terminateWorker()
{
worker.terminate();
worker = undefined;
}
testMainThread();
function testMainThread()
{
for (var i = 0; i < 200000; i++)
{
document.getElementById("loopcount").innerHTML = "Main Thread Counter: " + i;
}
}
And here is the worker.js file
i = 0;
while (i < 200000) {
postMessage("Web Worker Counter: " + i);
i++;
}