question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[docs] service-worker cache busting mini-guide

See original GitHub issue

Goal

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:

  1. 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.
  2. 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mesqueebcommented, Jun 16, 2020

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

0reactions
mesqueebcommented, Jun 16, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found