somebodysomewhere
somebodysomewhere

Reputation: 1146

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.

Upvotes: 15

Views: 9308

Answers (2)

Francesco
Francesco

Reputation: 10810

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.

Upvotes: 4

Mathias
Mathias

Reputation: 4569

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.

Upvotes: 5

Related Questions