Search code examples
progressive-web-appsdata-storagepersistent-storage

PWA persistent storage best practice


What is best practice for a PWA to store user generated data in a persistent way?

My app lets the user generate up to 5 MB of data that needs to be stored and accessed locally, but also backed up regularly in case the device gets damaged/lost, or the user accidentally wipes the data.

If I use FileSystemAPI or IndexedDB, is there some automatic backup system I can take advantage of? For example "Auto Backup for Apps" makes automatic backups on Google Drive for regular Android apps. Would be great if there is something similar available to PWAs.

In terms of user experience, does FileSystemAPI work well? I've read that even if the PWA is installed to the home screen, the user has to grant permission every session, which would be inconvenient.


Solution

  • If you want to store data persistently on the user's machine, consider using the Persistent Storage APIs. These APIs allow you to request permission to store data persistently. Any data stored there will be exempt from clearing browser data, for instance.

    Another possibility for you is the upcoming Native File System APIs. With those APIs, you can write to the file system, which again will be exempt from clearing browser data.