iframe是否可以与服务人员脱机渲染? [英] Can an iframe render offline with a service worker?
问题描述
我的网域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>
推荐答案
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
处理程序的FetchEvent
的request.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屋!