Alex028502
Alex028502

Reputation: 3814

get service worker id or date from within service worker

Does anybody know if there is a way to get this number or date inside the service worker:

chrome debug tools screenshot of service worker info

It would be handy to name my service worker cache either cache-1182 or cache-20171127171448

I guess the received date must be known before the install event.

Upvotes: 4

Views: 1829

Answers (1)

NOtherDev
NOtherDev

Reputation: 9672

No, this thing does not exist in the Service Worker specs so we must assume it is an internal implementation detail of Google Chrome, thus unaccessible.

To simplify, you might use installation timestamp as the version number and then look for cached resources in the cache marked with the newest timestamp. You can inspect all the cache keys with caches.keys().

Upvotes: 5

Related Questions