如何使用window.caches从window对象中保存页面? [英] How to use window.caches to save pages from window object?

查看:989
本文介绍了如何使用window.caches从window对象中保存页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保存app shell的大多数示例都显示了服务工作者的流程。但是我注意到你也可以从窗口访问缓存对象。

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?

推荐答案

这里有鸡与蛋的问题:你的网页可以读取和写入相同的缓存服务工作者可以通过 window.caches 访问,您需要服务工作人员拦截网页的初始导航请求,以便使用缓存对其进行响应。

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.

换句话说,使用 window.caches 预先假定您的页面已经加载,所以它没有帮助你在离线时加载页面。

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

这篇关于如何使用window.caches从window对象中保存页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆