UPDATE - Not sure how to update this to say pate's comment made me realise what I was doing wrong? Either way this is resolved for me now thanks
I return JSON from the server that contains a list of objects, each representing a digital post it note (text, position on page, database id etc.) I cache this in the service worker during fetch as normal.
Currently as users update/add post its I update a local copy of the JSON in the javascript as well as sending the info to the server.
What I want to do is as they update/add items the client JS will also save the new JSON to the application cache, then on page load use a cache-while-revalidate pattern so they only need to refresh if another user makes changes to their data. Otherwise they will get the cached JSON that will already contain their most recent changes.
As the application cache is versioned and the version number is stored in the sw.js file I'm currently sending a message (using MessageChannel) from the client to the SW to get the version number so the client can then put the JSON into the right cache. The only other options I can think of are to either make the application cache version a global variable somewhere other then the SW.js or just send the entire JSON in the message to the SW and let it put the update JSON into the cache.
Either way these all seem like workarounds/anti-patterns and I can't seem to find a better way of the client updating the application cache.
The other reason I want to do this is so that I can eventually move to an offline mode of working using the background sync api to handle add/updates etc. so want the cached JSON to be as up to date as possible.
Am I missing a trick somewhere?