Can an iframe render offline with a service worker?

我怕爱的太早我们不能终老 提交于 2020-06-25 17:27:13

问题


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

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.

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>

回答1:


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/.

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.



来源:https://stackoverflow.com/questions/44447482/can-an-iframe-render-offline-with-a-service-worker

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