Created
May 21, 2013 01:38
-
-
Save calvinmetcalf/5616996 to your computer and use it in GitHub Desktop.
Worker urls are resolved relative to the HTML not the script, here's how to write a script that can be called as js/scriptname.js and as scripts/scriptname.js. Still has to be same domain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof document === "undefined") {(function(self){ | |
self.onmessage=function(e){ | |
/* | |
worker stuff | |
*/ | |
} | |
})(self)} else {(function(exports){ | |
"use strict"; | |
function getPath(){ | |
var scripts = document.getElementsByTagName("script"); | |
var len = scripts.length; | |
var i = 0; | |
while(i<len){ | |
/* change --------> */if(/scriptWithWorker(\.min)?\.js/.test(scripts[i].src)){ | |
return scripts[i].src; | |
} | |
i++; | |
} | |
} | |
var worker = new Worker(getPath()); | |
/* | |
none worker code | |
*/ | |
})(window)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment