Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a Service Worker cache in Firefox?

In Chrome it is possible to clear the Service Worker cache from the Dev Tools.

How can we achieve that in Firefox?

I've tried so far:

  • to unregister the service in about:serviceworkers
  • to empty the cache under about:preferences#privacy
  • to reload the page with Ctrl + F5

but it's still there...

like image 305
Supersharp Avatar asked Jan 13 '17 14:01

Supersharp


People also ask

How do I clear a specific cache in Firefox?

to open the menu panel. Click History and select Clear Recent History…. Next to Time range to clear, choose Everything from the drop-down menu, select Cache in the items list, make sure other items you want to keep are not selected and then click the OK button.

Can I delete service worker cache storage?

So my answer is: Yes, you can delete it from Explorer. If you are worried about safety, you may at first step move the contents to a temporary folder and run Microsoft Edge. If everything works well, you may then delete the temporary folder. Note: Google Chrome behaves in exactly the same way.

Can I clear cache for just one website Firefox?

It is not possible to clear the cache for just one website, any clear operation that involves a cache clears the full cache. This even happens if you would use "Forget About This Site" to clear data from a specific website. With cookies and local storage this is possible, but for a cache this isn't possible.


2 Answers

Type this in the address bar of Firefox and deregister the service workers you want.

about:debugging#workers 

EDIT: In newer versions #worker anchor does not works. You will have to scroll down to Service Workers section.

like image 194
coder3101 Avatar answered Sep 22 '22 02:09

coder3101


You can execute following code snippet in Firefox Web Console:

caches.keys().then(function (cachesNames) {   console.log("Delete " + document.defaultView.location.origin + " caches");   return Promise.all(cachesNames.map(function (cacheName) {     return caches.delete(cacheName).then(function () {       console.log("Cache with name " + cacheName + " is deleted");     });   })) }).then(function () {   console.log("All " + document.defaultView.location.origin + " caches are deleted"); }); 

For more information about this code snippet check Cache Web API page on MDN.

You can't clear Service Worker cache using Storage Inspector in current version of Firefox. See Storage Inspection documentation about currently available features. You can't use about:preferences#privacy or unregister Service Worker because Service Worker cache works independently of browser HTTP cache and managed only by your scripts. Relevant excerpt from Service Worker specification:

5.2 Understanding Cache Lifetimes The Cache instances are not part of the browser's HTTP cache. The Cache objects are exactly what authors have to manage themselves. The Cache objects do not get updated unless authors explicitly request them to be. The Cache objects do not expire unless authors delete the entries. The Cache objects do not disappear just because the service worker script is updated. That is, caches are not updated automatically. Updates must be manually managed. This implies that authors should version their caches by name and make sure to use the caches only from the version of the service worker that can safely operate on.

like image 43
Leonid Vasilev Avatar answered Sep 23 '22 02:09

Leonid Vasilev