[docs] service-worker cache busting mini-guide
See original GitHub issueGoal
always ensure a certain website displayed to visitor is the latest version, and not an old cached version (eg. with your main.js
logic from a previous version)
Methods
are two ways I believe this is possible to implement:
- make an API call that checks the version on a server/cloud function and returns the version which is to be checked against a version saved in the localStorage. If they don’t match prompt to reload the page.
- use a service worker.
Service worker approach
I believe the common approach with a service worker is to expand a bit on the updated()
hook like so:
updated() {
console.log('New version needs refresh.');
Notify.create({
title: 'New version available: ' + require('./../package').version,
actions: [
{
label: "Refresh",
handler: () => window.location.reload(true)
}
]
})
},
Request
I’m personally however very confused on how to do the whole “check the hash of the app against the new version of the service worker” or something.
There are many articles on this, but they all say different things, and the part about automatically exposing and checking against a hash of some sort is still confusing to me.
I’d love this to be an extra section on the handling-service-worker documentation page of Quasar!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Service worker caching and HTTP caching - web.dev
A service worker intercepts HTTP requests with event listeners (usually the fetch event). This code snippet demonstrates the logic of a Cache- ...
Read more >Strategies for service worker caching - Chrome Developers
A caching strategy is an interaction between a service worker's fetch event and the Cache interface. How a caching strategy is written depends; ......
Read more >Service Worker Cache Busting | Jun711 blog
To do a service worker cache busting, we only need to clear cache unless you want to remove cookies and storage too (which...
Read more >Service worker configuration - Angular
The default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used,...
Read more >Why We Avoided The Angular Service Worker - shusson.info
Cache busting with a webserver like nginx doesn't help, since navigation inside the application is intercepted by Angular.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s Firebase Hosting apparently that caches
index.html
which is why my old.js
files are being loaded, even when Quasar has hashes in their names.Problem solved by this thread:
https://stackoverflow.com/questions/48589821/firebase-hosting-how-to-prevent-caching-for-the-index-html-of-an-spa
Is it possible to add just the service worker to an SPA as well? Or do the usage of service workers require an app-manifest to exist as well?
I have some cases where somehow even SPAs sometimes are not loading the latest main.js but serve from cache instead. I want to prevent this by showing an “refresh for latest version” notification.