Skip to content

Instantly share code, notes, and snippets.

@Xanir Xanir/Load Script Worker
Last active Mar 7, 2019

What would you like to do?
var scriptId = 'api-base-path';
var scriptElem = document.querySelector('script#' + scriptId)
var scriptBlob = new Blob([scriptElem.innerText])
var scriptURL = URL.createObjectURL(scriptBlob)
var res = await fetch('worker.js');
var script = await res.text();
var scriptBlob = new Blob([script]);
var scriptURL = URL.createObjectURL(scriptBlob);
var worker = new Worker(scriptURL);
return worker;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.