instantpage / instant.page

Make your site’s pages instant in 1 minute and improve your conversion rate by 1%
https://instant.page
MIT License
6.01k stars 206 forks source link

Prevent preload while website is offline #73

Open ghost opened 4 years ago

ghost commented 4 years ago

Issue

I use instantpage.js on my blog that has a service-worker to implement offline functionality. In case a user accesses my website offline I receive a net::ERR_INTERNET_DISCONNECTED error in the preload function when instantpage.js tries to prefetch a resource.

Expected

As a website owner, I want to only prefetch URLs when I am online, so that I am not getting network errors when my site is offline or served by a service-worker.

Potential solution

To show a potential solution I created a pull request that implements a guard in the preload function to disable preload when the navigator is offline (https://developer.mozilla.org/de/docs/Web/API/NavigatorOnLine/onLine). I don't know if it is be possible to prefetch directly from the service-worker cache in this case, but I guess prefetching only makes sense when you are online anyway (of caused to be discussed!).

I am a part time developer so the adjustment should be deeply checked and tested!


KR and thanks for making and maintaining this awesome script!

ghost commented 4 years ago

Sorry, I am new to pull requests so I created one on my fork and then another directly on this repository!