Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is truly persistent storage possible in a progressive web app?

I was reading this guide on offline storage for PWA's that described two storage API's, the Cache API and IndexedDB, however it seems that neither storage option is truly persistent. The Cache API is temporary by design, and the IndexedDB data can be wiped when the user clears their browser cache.

So, is it possible to have truly persistent storage in a PWA? What I'm trying to do is this:

  1. User visits my website on their smartphone and I generate a unique ID in JavaScript.
  2. They press "add to homescreen" on iOS or press the "add to homescreen" bar on Android.
  3. The PWA gets added to their phone. At this point, I would like to store that unique ID persistently.

Is there any way that I can do so? Maybe an API that I don't know about? I only need a tiny unique code, since this PWA is not designed to have users log in with cookies.

like image 279
somebodysomewhere Avatar asked Jun 21 '19 18:06

somebodysomewhere


Video Answer


2 Answers

No
The user can delete the PWA (if installed on Android) and clear their browser's cache of everything from your PWA.
Then if they visit again you would need to generate a new ID for them.
But you would know nothing of their previous ID if you have no login back end tied to unique users.

like image 106
Mathias Avatar answered Nov 26 '22 21:11

Mathias


As Mathias already stated, it is not possible to achieve your goal with just PWA, as the user can wipe all the previously generated data.

So, long story short, you must use some other solution to ensure "truly persistence storage".

For example in a personal PWA Project of mine, I use Cloud Firestore. It offers also a very generous free tier you can use and it even allows offline persistence, granting full CRUD operations to your application (even when offline!).
Service Workers, through the Cache API, allow to cache only GET Requests, but no POST.

I wrote another answer about this on SO. And here you can find the official documentation.

like image 36
Francesco Avatar answered Nov 26 '22 21:11

Francesco