GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 331 forks source link

maxAgeSeconds in sw-toolbox #207

Open numberknot opened 7 years ago

numberknot commented 7 years ago

In reference to Stack Overflow, All resources are getting cached as expected but they are not expiring on putting maxAgeSeconds. I have used CacheFirstStrategy, and verified that resources are kicking in through service worker cache. Also, I can see number of other cache storage (explicitly deleted caches using caches["delete"](e) ) in Application Tab->IndexDB which is not getting return by this statement caches.keys().then(function(e) { console.log(e); })

jeffposnick commented 7 years ago

Thanks for reporting this. Some more information would be appreciated to get to the bottom of it.

If you can reproduce this behavior on a publicly deployed site, can you provide the URL?

If you don't have it deployed anywhere, can you provide your sw-toolbox configuration, as well as a screenshot of both the Cache Storage and IndexedDB panels in the Applications tab of Chrome DevTools? Any log messages in the JS console would be useful as well.

addyosmani commented 7 years ago

Friendly ping @PrototypeChain as we'd love to understand if more info from when you ran into this issue is available. It'd help us ensure we don't replicate whatever was causing it as we work on the next version of these libraries.

sohin-keshwani commented 7 years ago

Hi, Following up on this ticket. We have implemented the same caching strategy. When doing a hard refresh we get the fresh content while in normal cases we get the stale data. We have kept the TTL to 300 seconds. Below is the code for it

https://www.voot.com/service-worker.js

self.toolbox.router.get('/(.*)/getMegaMenus.json', self.toolbox.cacheFirst, { origin: /\.voot\.com/, "cache": { name: 'voot-assets-menu-js', maxEntries: 5, maxAgeSeconds: 300, }, });

Attached are the screenshots where in one of the screenshots you can see under Voot Originals -> Yo Ke Hua Bro which appears after the hard refresh

uncached-data-from-sw cached-data-from-sw

PS: Our website is restricted to India only as of now, incase you need to visit, you will need to use an Indian proxy.

jeffposnick commented 7 years ago

I can't view https://www.voot.com/service-worker.js due to the georestrictions.

First, what version of sw-toolbox are you using? There's code that checks whether a cached response is "fresh" before using it, but that was added in release 3.5.0.

Assuming you're using 3.5.0 or later, can you confirm that your cached responses have proper Date: headers set on them? The code to check whether a cached response is "fresh" relies on the Date: header being available.

sohin-keshwani commented 7 years ago

Thank you @jeffposnick to point this out. Will take it up and keep you apprised about the development.