jimmywarting / StreamSaver.js

StreamSaver writes stream to the filesystem directly asynchronous
https://jimmywarting.github.io/StreamSaver.js/example.html
MIT License
3.98k stars 413 forks source link

Does this lib works without internet connection? #126

Closed mobilekosmos closed 4 years ago

mobilekosmos commented 4 years ago

"So StreamSaver creates a own man in the middle that installs the service worker in a secure context hosted on github static pages."

Based on above from the main page isn't clear now how this lib works, I expected a lib that would work locally without internet connection, so this is not the case?

blubbll commented 4 years ago

The mitm is just a html file. The serviceworker just a javascript. You can host both offline.

jimmywarting commented 4 years ago

service worker is built for taking your PWA offline so it could be possible to cache mitm after the service worker have been installed and then after that it will work offline, but it isn't implemented...

One possible reason why I haven't done it yet might just be that it's lazy loaded on demand. and it isn't installed right away when you visit the site. - i could do it doe if it's requested

The alternative is what @blubbll mention host both files yourself. And configure StreamSaver to use it's own mitm streamsaver.mitm = '/my-mitm.html' so it works on localhost and no connection will ever be needed.

but if you are building a semi-offline app with service worker and that is installed once someone visit your site then you could try to embed my sw.js into your own service worker and kinda merge them togheter somehow.


one benefit of having a self hosted sw.js could be that you wouldn't need any mitm or a iframe and be able to talk directly to the sw.js but streamsaver wasn't built that way from the start (for easier usage, rapid prototyping so you could just including a cdn script tag or just importing a npm package without setting up your own service worker. it was also done so insecure sites could use it too)