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

…衆ロ難τιáo~ 提交于 2019-12-07 20:46:47

问题


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:


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.



来源:https://stackoverflow.com/questions/44239518/how-to-use-window-caches-to-save-pages-from-window-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!