stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.91k stars 169 forks source link

This doesn't completely work offline. #992

Open real2two opened 1 year ago

real2two commented 1 year ago

Is your feature request related to a problem? Please describe: In a numerous amount of pages, WebContainers claims to work when you're "offline". There's a catch though. WebContainers doesn't completely work offline. I'm not filling this out as a bug report because I don't know if it's intentional or not. image (from https://webcontainers.io/guides/introduction#webcontainers-versus-cloud-vm-approach)

For example: If your internet goes offline while you were testing on localhost and need to reload to see your changes, the WebContainer will no longer load, because: image

Another problem is when you want to load another port while you're offline. When you load a new port, the page won't load because it tries to load a new link (while you're offline). The reason why the page loads with the same port (while you're offline) is because it uses the same link and WebContainers works with PWAs.

I think it would be really useful if WebContainers completely worked offline (eg. electron apps), because I want to be able to build desktop application that can run offline and run user created scripts safely (eg. games).

Describe the solution you'd like: I can't really think of too many solutions, but here's one solution:

Describe alternatives you've considered: Not really.

Additional context: None

Aworldc commented 1 year ago

this is what i absolutely need.

cemalgnlts commented 1 year ago

Any progress on that?

liudonghua123 commented 1 year ago

I also would like to make it work offline. Now it needs network to connect to stackblitz to request some resources like the following now.

image

Can we self host the static files and use webassembly like pyodide to serve some dynamic request locally. In this way, no serve resources needed.

More and more features and capabilities are moved to the local or browser, like WebGPU (see also https://mlc.ai/web-llm/) and so on. Maybe it's a new way to rethink or redesign the app.

alexjbuck commented 1 year ago

I haven't dug into the files that are downloaded initially or on reload, but, when the stackblitz PWA is installed, couldn't the service worker implement a cache policy and proxy all of those fetch requests to the cache if the network response fails?

This is the strategy I've used for other "full offline" PWAs.

Unless something during runtime requires network access, I think that would do the trick.

oceangravity commented 1 year ago

Hi! I also tried to make it completely offline without success. Load times can be drastically reduced by doing this. In my case, I'm just using a Vite server where files are loaded dynamically, but the rest of the files don't change every time, except maybe when Vite has a breaking change.

I hope this can be managed or fixed in some better way 🙏

image

thanks guys!

K3BAP commented 7 months ago

Any progress on this? I am working on a learning environment which will be used in places where the internet connection will be either very slow or just not present. Would be very useful if I could use the library without the need of an internet connection.

cemalgnlts commented 7 months ago

I think doing it completely offline will ensure that they can't make anything commercially out of the project. So I don't think they are very positive about it.