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.

1
  • To clarify these are external URLs on different domains out of my control. Commented Mar 14, 2017 at 16:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Can these handle URLs from other domains?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.