Relative URL handling
guybedford opened this issue · 2 comments
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:
new Worker(new URL('./rel.js', import.meta.url))
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:
- Allowing a URL object into
new Worker
(does the browser call toString? I think it might?) - Changing the readme to use this pattern in the example
- Removing the stack hack
Let me know if you might consider the above, I'd be glad to contribute too.
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 #5.