forked from mrtnbroder/shared-worker-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateInlineWorker.js
More file actions
23 lines (22 loc) · 776 Bytes
/
createInlineWorker.js
File metadata and controls
23 lines (22 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string
var URL = window.URL || window.webkitURL;
module.exports = function(content, url, name) {
try {
try {
var blob;
try { // BlobBuilder = Deprecated, but widely implemented
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
blob = new BlobBuilder();
blob.append(content);
blob = blob.getBlob();
} catch(e) { // The proposed API
blob = new Blob([content]);
}
return new SharedWorker(URL.createObjectURL(blob), name);
} catch(e) {
return new SharedWorker('data:application/javascript,' + encodeURIComponent(content), name);
}
} catch(e) {
return new SharedWorker(url, name);
}
}