According to the information provided on the https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage page:
The CacheStorage interface serves as the storage for Cache objects, maintaining a directory of all named caches accessible to ServiceWorker, other types of workers, or window scopes. While it is primarily used with service workers, it can be accessed through other means as well.
I am curious - is it more advantageous to utilize cacheStorage within a ServiceWorker compared to within a Window scope? If so, why?
As nobody seems to have an answer, I'd like to share my thoughts on this matter.
In my personal opinion, there are several benefits to utilizing ServiceWorker.
Firstly, the fact that ServiceWorker operates on a separate thread makes it more efficient.
Additionally, integrating ServiceWorker into an existing website is much easier without the need to rewrite code, unlike when implementing it in a window scope where modifications to Ajax code may be necessary.
Lastly, you can continue running operations even after the page has been closed. For instance, you could store data in the cache upon receiving a push notification.
Despite these advantages, I am still puzzled about why browsers allow access to cache from window scopes. Is it simply for convenience, enabling us to operate solely in the main thread? Or does this pose a security risk, potentially granting hackers access to cached data in instances of cross-site scripting attacks?