Best way to invalidate cache of main.js and others in an PWA?

I was wondering what ways other devs are using in order to make sure that the browser loads the newest version of main.js,…

  1. My first idea was to add something to the webpack conf that adds a hash on each file name if something changed. Like main-ABCDE123.js would be sure to be loaded because it has never been in the browser cache. Not sure yet how to do this and if it would break something in ionics lazy loading?

  2. I don’t use service workers yet but I saw that once the service worker changes you get an event that service worker is ready to update, so maybe the service worker could manage the cache invalidation?

Would be great to hear how you handle this, because switching of cache in the browser or forcing non cached files from the server doesn’t seem like a permanent solution.

1 Like