2

I have created a progressive web app that simply lists links (to URLs) that when clicked uses the default browser of the device (say mobile phone) to open the URL.

Is there a way to tell the device to cache these pages so they are available offline.

This is so when my progressive web app runs offline, any links previously visited will also be able to display in the devices default browser.

Jay Byford-Rew
  • 5,736
  • 1
  • 35
  • 36

1 Answers1

1

You can do two things:

  1. Pre-cache the set of links; you can do that using a library such as sw-precache
  2. In the fetch event handler of the Service Worker of your PWA, place the URL's the user clicks on in the cache.

Option (1) has the advantage that your app will be offline-ready from the the start; and option (2) has the advantage that your app will cache only the links the user was interested in. I think your question refers to option (2); depending on your use cases, you can decide on which strategy is best.

You can lear more about a variety of caching and serving strategies in Jake Archibald's Offline Cookbook article.

  • Can these handle URLs from other domains? – Jay Byford-Rew Mar 15 '17 at 08:54
  • Yep; the SW is a client-side programmable proxy and you have complete control of it; the fetch event handler will intercept all requests made for either your domain or others. – Alberto A. Medina Mar 15 '17 at 13:18
  • The SW can handle requests from your site to other domains. However if the user navigates to a different domain the SW for your app will not be able to handle those requests. – abraham Mar 15 '17 at 15:45