Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use window.caches to save pages from window object?

Most examples of saving an 'app shell' show the process from a service worker. However I noticed that you can also access the caches object from the window.

So my question is, can I save pages for offline from the a page itself, and if so, what is the point of a service worker if this is possible?

like image 973
Niels Avatar asked Dec 15 '25 04:12

Niels


1 Answers

There's a chicken-and-the-egg problem here: while your web pages can read from and write to the same caches that a service worker has access to, via window.caches, you need a service worker to intercept the initial navigation request for a web page in order to respond to it using the cache.

In other words, using window.caches presupposes that your page is already loaded, so it doesn't help you load the page while offline.

like image 168
Jeff Posnick Avatar answered Dec 16 '25 22:12

Jeff Posnick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!