Prevent preload while website is offline
Opened this issue · 1 comments
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!
Sorry, I am new to pull requests so I created one on my fork and then another directly on this repository!