PWA: How to store pdf in local storage or local device with Javascript/HTML 5?

4k Views Asked by At

I am setting up a progressive web app with PWA Builder. I need to download pdf, once I Progressive web app downloaded on the local device after disconnected internet than I check again click to the link of pdf for downloading. I tried but the PDF file doesn't download. Please suggest.

1

There are 1 best solutions below

6
On

First of all, I think you must have internet connection to download pdf first. Then, convert it to base64 and store inside localStorage. Once user open your web app again, check if he/she open same pdf as we stored, show it from localStorage.

Edit: I don't think you couldn't be able to cache in service worker. That's only for predefined data.

There's two more options: - websql - indexsql - pouchsql

https://www.sitepoint.com/offline-web-apps-service-workers-pouchdb/