Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Reading sw.js URL from query string for simpler self host #255

Closed
yume-chan opened this issue Dec 9, 2021 · 1 comment

Comments

@yume-chan
Copy link

yume-chan commented Dec 9, 2021

Usually self host StreamSaver means manually (or use copy-webpack-plugin) copy mitm.html and sw.js to public folder and set up StreamSaver.mitm = '/static/mitm.html'.

But with Webpack 5 and URL Assets, one can do something like

StreamSaver.mitm = new URL('streamsaver/mitm.html?url', import.meta.url).toString() + '?sw=' + new URL('streamsaver/sw.js?url', import.meta.url).toString();

And Webpack will automatically copy mitm.html and sw.js to public folder. One bonus point is that these files now have names with hashes so they can be cached forever.

However, the sw.js path is hardcoded so the above code doesn't really work.

return swReg || navigator.serviceWorker.register('sw.js', { scope: './' })

I have tested locally that some thing like this is possible (although URLSearchParams may have compatibility issue)

return swReg || navigator.serviceWorker.register(new URLSearchParams(location.search).get('sw') || 'sw.js', { scope: './' })
@yume-chan
Copy link
Author

Actually service worker script URL shouldn't change. So closing in favor of copying deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant