Building a Progressive Web App in React, using Firestore for offline support
blog.truthlabs.com
blog.truthlabs.com
The real problem with all of these systems is that it's very hard to get arbitrary offline mutations "right." For instance, a GraphQL mutation changing nested objects would likely need to translate to a database transaction... and although Firestore supports such transactions, it doesn't support them offline: https://firebase.google.com/docs/firestore/manage-data/trans...
Of course, if you can structure your data such that it can be represented by a CRDT - https://en.wikipedia.org/wiki/Conflict-free_replicated_data_... - offline sync comes much more naturally. https://irisate.com/crdt-for-real-time-collaborative-apps/ is a great writeup that includes links to some actively-developed JS libraries.
"By default, the production build is a fully functional, offline-first Progressive Web App."
For building a UI, you could do worse than starting with one of the following:
- http://package.elm-lang.org/packages/debois/elm-mdl/latest
- http://package.elm-lang.org/packages/rundis/elm-bootstrap/la...
- more at e.g.: https://www.reddit.com/r/elm/comments/7713wm/elm_ui_libs/
It's all open-source: https://github.com/hackundsoehne/talKIT-Event-App beware, I was under a lot of pressure and often it's quick an dirty.
I built the whole thing in 2-3 days, including the backend.
Our project: https://chatbird.io (PWAs are not communicated on the landing page yet since we started with bots)
https://en.wikipedia.org/wiki/Progressive_enhancement
The idea to progressive enhancement (to me - I understand these terms weren't unambiguous even as they emerged) is that you start with content, add structure (HTML), and slowly "enhance" to higher and more elaborate UI features (CSS, javascript). You add each layer in a way that you can always fall back to a simpler method or rendering. It is not necessary to render the structure to access the content. It is not necessary to render the styling to access the structure. It is not necessary to render the interactivity to access the styling.
Now, a web app built progressively doesn't necessarily meet the criteria for progressive enhancement, since plenty of people add html, css, javascript, and beyond without preserving the ability to render from a previous stage. But I think people have confused the ability to render to a previous stage with progressive enhancement as well. It's a good quality in a javascript framework that you can still view your site in lynx or with a pure html browser, but writing your app upfront in a JS heavy manner and relying on the framework to fall back for you? I think that's something other than "Progressive Enhancement", because you didn't enhance your app progressively, you started at the highest level of UI. I'd call that a "backwards compatible" web app.
Obviously this could all be solved by applications loading their content via a javascript cache, but then you are putting a hard dependency on javascript, service workers allow you do do the age old <img src="profile.jpg" its going to work in all the browsers, but if your browser supports service workers it can upgrade that <img src=" to load data from cache when offline
tl;dr service workers allow you to add dynamic caching to existing web content via progressive enhancement
Web Workers are used to offload work to another thread and can communicate with messages
Service Workers is a new API which is now supported by all major browsers.
SW is branded as: Rich offline experiences, periodic background syncs, push notifications and more. "A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction."
Full article on this topic: https://developers.google.com/web/fundamentals/primers/servi...
The way I've (over?)simplified explaining ServiceWorkers to people is that they're like a proxy application running between your browser tab and the actual web service (server).
They can see/intercept/manipulate requests and responses, and have their own cache. This obviously enables offline mode (the request goes through the ServiceWorker and can be responded to without contacting the web if there's a cache), but also potentially quite a few other features and ideas.