hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
431 stars 49 forks source link

Offline simplified #78

Closed jayohms closed 4 years ago

jayohms commented 4 years ago

This removes the HTTP caching strategy, since it's not as reliable as APP caching and adds overhead. Turbolinks now provides the app with an InputStream to cache, instead of a ByteArray. This means that the stream can be written directly to file without exploding the app's memory and isn't subject to memory limits.

When the app caches a response, it's responsible for returning the cached File's InputStream, since the original network InputStream will be consumed and closed while caching.

sedubois commented 3 years ago

If Turbo allows building an app with offline functionality, it sounds like a feature very much worth highlighting 🙂 Is there any doc/demo showing how it works and what use cases it supports? Is there any support in web/iOS? A search for "offline" in turbo and turbo-ios does not yield any results.

jayohms commented 3 years ago

@sedubois Good question 😉. We have built offline caching support into the HEY Android and iOS apps. On Android, it made sense to build hooks directly into the turbo-android library, since the WebView APIs allow intercepting HTTP requests directly. This functionality is still experimental, since it requires quite a bit of app code outside the library to function. Eventually, I'd like to move this directly into the library so providing offline support is trivial for other apps.

The iOS side is more complicated, though. The WKWebView APIs do not allow intercepting HTTP requests, so the HEY iOS app has to run a local proxy server to provide offline support. This makes it impractical to include it in the turbo-ios library right now. Hopefully this situation will improve in future iOS updates.

So, for now, it's not a feature we want to advertise or recommend because the implementation is not straightforward and does not have parity across platforms.

sedubois commented 3 years ago

Thanks so much @jayohms for your time. One thing is sure, we'll continue to integrate with Hotwire, but I'm quite desperate regarding how to implement offline in our own app, which we very much need.

I find it important to support older devices so I wouldn't wait for a fix in some new iOS version. If there's any pointers you'd be willing to share now or later regarding your custom iOS/Android implementations, in particular the proxy server setup, I'd be very grateful.

At least it's great news to hear there is one example "out there" of a Hotwire app working offline 🙂