Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  164] [ 6]  / answers: 1 / hits: 125454  / 7 Years ago, wed, august 2, 2017, 12:00:00

So, I have an HTML page with service worker,
the service worker cache the index.html and my JS files.



The problem is when I change the JS, the change doesn't show up directly on the client browser. Of course in chrome dev-tools, I can disable cache. But in chrome mobile, how do I do that?



I tried to access the site settings and hit the CLEAR % RESET button.
But it still loads the old page/load from cache.
I tried to use other browser or chrome incognito and it loads the new page.



Then, I try to clear my browsing data (just cache) and it works.



I guess that's not how it should work right? my user won't know if the page is updated without clearing the chrome browser cache.


More From » html

 Answers
7

Use this to delete outdated caches:



self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});

[#56890] Monday, July 31, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;