andi17 andi17 - 10 days ago 10
Dart Question

How to build an offline supporting web application with AngularDart

We have been starting out on building a simple web application on AngularDart 2.

What is the best way to have it runnable on the clients even though they lost internet connection? Right now I am using Lawndart library to use the local storage for saving some data received from REST-Api and it's working fine. But I haven't figured out how to tell the client browsers to cache all sources and use them when having no internet connection. (Right now I am simply using my Redstone-Dart Server (on which the REST-Services are running) for providing the sources)

I've stumbled upon the Angular Mobile Toolkit (https://mobile.angular.io/guides/), but it is only for TypeScript, or is there a way to use it with Dart?

Also later in the project it might be necessary to send push notifications to the clients...is this possible with Dart and Angular 2?

Answer

Regarding the following point:

cache all sources and use them when having no internet connection

Although deprecated and having a bad reputation, I still personally use AppCache (https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache). I understand the solution looks so 2005 when people talk about progressive apps and service worker. It is the only cross-browser solution that works now.

It is easy to setup (just serve a manifest.appcache). For angular application, it mostly contains index.html, main.dart.js and external dependencies. For me it works on Safari, Chrome and Firefox (cannot tell for IE/Edge). As iOS was a need for me, I could not find another alternative (service worker). Chrome is starting to send a warning for non https sites but so far so good.

Real push notifications are more complex in a web environment; I personally use Firebase realtime database to "push" updates