In my PWA development project, I am looking to provide users with the option to download and cache all media assets used in the application. However, the default behavior of PWAs only caches assets when they are requested during app navigation. My goal is to allow users to press a button, download all assets, go offline, and still be able to use the entire app with all assets cached without having to visit different routes online.
At the start of the app, Vuex retrieves JSON content from my API, stores it in state, and saves it to IndexedDB for later access.
If a user clicks on the 'download everything' button, I plan to extract URLs (such as images, PDFs, and MP4s) from $store.state, compile them into an array, and then pass this array to the ServiceWorker to intentionally cache all assets at those URLs for offline usage (within the allowed origin storage limit).
My project utilizes Vue CLI and the Vue PWA plugin, which includes a registerServiceWorker.js file and generates a precache manifest for production purposes.
While researching this topic online, I came across some information that was a bit confusing. I am considering following the approach outlined in this guide from Google Developers, but I have certain uncertainties about the specifics. Additionally, I'm unsure how to seamlessly integrate this process within the Vue CLI workflow.
If possible, could you address the following questions in your response:
Should I use GenerateSW or InjectManifest?
Is it necessary to create a custom Service Worker, or can I leverage lifecycle methods (such as registered(), cached(), updated()) within registerServiceWorker.js?
I greatly appreciate any assistance you can offer. Thank you.