Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an iframe render offline with a service worker?

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>
like image 873
Daniel Rasmuson Avatar asked Jun 09 '17 00:06

Daniel Rasmuson


1 Answers

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.

like image 185
Jeff Posnick Avatar answered Nov 13 '22 06:11

Jeff Posnick