Closed guybedford closed 4 years ago
Good point, definitely would prefer to push folks to use that pattern.
I can throw the stack hack thing into another package - I've found some cases where doing it without that gets really ugly, but it's the wrong thing to push folks towards for sure.
I was thinking of Thursday for a release date - think you'd have a chance to throw a PR together be then? If not I can make the changes and run them by you.
Thanks for being open to it! I've created a PR at https://github.com/developit/web-worker/pull/5.
I see you are using the stack trace hack currently to determine the relative URL.
The issue with this approach is that it doesn't actually match what the browser does which is to resolve
new Worker('./rel')
relative to the page, not the URL of the module that does the worker instantiation.As a result, the best approach for a cross-browser worker instantiation is actually something like:
I would really like to see us encouraging the above pattern as something tools and environments can get behind. Build tools can easily then parse and optimize this pattern with a simple detection.
This would involve the following changes:
new Worker
(does the browser call toString? I think it might?)Let me know if you might consider the above, I'd be glad to contribute too.