iframe是否可以与服务人员脱机渲染? [英] Can an iframe render offline with a service worker?

查看:66
本文介绍了iframe是否可以与服务人员脱机渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网域123.com中有我的域abc.com和一个iframe.我拥有每个域的代码.

I have my domain, abc.com, and an iframe inside my page 123.com. I own the code for each domain.

借助服务工作者,即使脱机时我也可以加载abc.com,但是即使我将其文件添加到cache.addAll调用中,我的123.com iframe也无法加载.

With a service worker I can load abc.com while offline but my iframe for 123.com does not load, even if I add its files to my cache.addAll call.

如何使我的iframe离线显示?示例欢迎.

How can I get my iframe to render while offline? Examples welcome.

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    will render offline

    <!-- will not render offline -->
    <iframe src="123.com"></iframe>
  </body>
</html>

推荐答案

加载<iframe>

Loading an <iframe> is very similar to loading a full page in a new tab/window. The request for the <iframe>.src will trigger any fetch handlers on a service worker whose scope covers the <iframe>.src, i.e. in your case, a service worker whose scope covers https://123.com/.

传递给fetch处理程序的FetchEventrequest.mode'navigate',就像导航到独立的选项卡/窗口中的新页面一样.

The FetchEvent that's passed to the fetch handler will have a request.mode of 'navigate', just like a navigation to a new page in a standalone tab/window would have.

这篇关于iframe是否可以与服务人员脱机渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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