Search code examples
vue.jsvuejs2vuexservice-worker

service worker caching vs VuexPersistence


I guess it's a silly question as I could not find the topic anywhere, but I am currently learning about service workers and caching features, and was wondering if VuexPersistence was still needed if you implement all your caching strategy with sw? Are they comparable, what make them different? And when should I use one instead of the other?


Solution

  • VuexPersistence:

    stores the data in your Vuex-Store, inside your Browsers localStorage and makes it reusable. Example: you have a JWToken stored in your Store, wich is then also stored in your localStorage.


    ServiceWorker:

    is caching the HTML at your side. It means it allows the browser a faster representing of the website like it would usually. Normally on visiting a SPA you download the whole stuff at the beginning and only fetch data. If you close the browser now, the "SPA" is lost and need to be redownloaded on next visit of the SPA.

    ServiceWorker is caching this very SPA inside your Browser and allows a faster Clientside performance.