Story
I got a website using traditional browser cache, the site is heavy cached, up to 365 days for static content.
And to purge the cache after new version deployed, I am using a query string of version identifier like:
<script src="js/main.js?version=1.3.0"></script>
But for every upgrade of version, the load time is bad because browser need to download all the new contents when query string changed.
Situation
Now, we got Service Worker, and I've integrated it into my website. All is OK so far, the query string of version identifier still got using.
// simply cache all the static contents
global.toolbox.router.get('/', global.toolbox.networkFirst);
global.toolbox.router.get(/(.js|.css|.png|.jpg|.json|.html)/, global.toolbox.fastest);
And the same behavior still presenting just like before SW integrated. And yet the upgrade is slow like it always do...
Question
And I am wondering if there are any better approach? which can do something like below and still keep the heavy cache mechanism (for old browsers):
- New version found
- Still use the old content of latest version,
- Under going fetch all the new content of new version,
- Next time user visit the site, they will use the latest version.
NOTE The goal it to load the site faster when a new version deployed