How to use window.caches to save pages from window

2019-05-25 05:59发布

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?

1条回答
神经病院院长
2楼-- · 2019-05-25 06:31

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.

查看更多
登录 后发表回答