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.

Service worker: delete index.html from cache in onupdatefound event

See original GitHub issue

Is your proposal related to a problem?

When the service worker in registerServiceWorker.(js|ts ) is enabled it provides very useful PWA benefits.

However, in a production build it also caches the index.html file which references the names & hashes of the outputted JS chunks by the webpack build. When a new build is created, new chunks and hashes are generated, however, the service worker at the client keeps the old index.html and looks for the old chunks, which completely breaks the app as no JS can be obtained.

Describe the solution you’d like

The registration of the service worker in registerServiceWorker.ts already detects new content available from the server and logs a prompt to refresh in the console. In the onupdatefound event here there is an assumption that old content has been purged, when in fact even after closing all tabs and hard reloading I keep seeing this message and when I check the cache in DevTools and the network I see it’s coming from the service worker. Other issues can be found here #7121 #4674 #5316 which can’t get past this issue as well.

At the event handler as well as the console log of New content is available; please refresh., it would be better if index.html is manually deleted from the cache using the Cache API, the cache key seems to be in the form of workbox-precache-https://mysite.io/.

Describe alternatives you’ve considered

Turning the service worker off takes away a lot of benefits and PWA functionality, so it’s not really an option as proposed in other issues related to this.

Many thanks 😃

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:32
  • Comments:15

github_iconTop GitHub Comments

19reactions
tobias-tenglercommented, Jun 5, 2020

This issue should be high priority IMO. All it takes is for a developer to include serviceWorker.register();, deploying that version, people visiting that version of the site, pushing a new update and now the app is broken for everyone that previously visited that site. Seems like something really bad! And the worst part: afaik the serviceWorker can’t be easily disabled for people that are already affected by this.

12reactions
mexmirrorcommented, Mar 30, 2020

Our project is currently affected by this as well. Wouldn’t it be a good default implementation if this was enabled by default? Correct me if I am wrong, but when we deploy the application, the bundler creates new bundle names which will break any cached index.html.

Read more comments on GitHub >

github_iconTop Results From Across the Web

exclude index.html from service worker cache in create-react ...
I think caching the index.html using the service worker is the issue but have not been able to exclude it from getting cached, ......
Read more >
How to clear a service worker cache for index.html page?
I just inherited a website where the whole site (including index.html) is cached by a service worker. I deleted the old website and...
Read more >
The service worker lifecycle - web.dev
A service worker won't receive events like fetch and push until it successfully finishes installing and becomes "active".
Read more >
Flawless and Silent Upgrade of the Service Worker
If the Service worker updates not fast enough, old HTML or old ... in the old service worker's cache storage with the most-recent...
Read more >
Using Service Workers - Web APIs | MDN
Using a service worker you can set an app up to use cached assets first, ... if index.html makes a cross-origin request to...
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