How to download the complete html page in JS/React-Native?

Viewed 6163

So I am trying to download a complete HTML page in a React-Native app , so that the user can view the page later when they are offline too. I am rendering the page using WebView and it works without any issues when online.

For getting it offline, I am doing a axios.get to fetch the page and I'm storing it. But when I'm rendering this page I noticed that its missing all the css/images since, they were not part of the GET request. How can I download the complete HTML page and render it as it were online?

I'm not able to think of any way to download all the page's assets.

2 Answers

You need to download all referenced assets and possibly change references so they work locally. There are a few tools that can do this.

The simplest way is probably by saving the website using your web browser. This may or may not work the way you expect but it’s worth trying.

If it’s not enough, try tools like HTTrack or wget. Instructions here.

it similiar with my current issue, im facing with long time download aset time when user try to open the webview, its reduce UX anyway, then we should do something for better performace, and i found this package

https://www.npmjs.com/package/react-native-static-server

but i worry about the long term maintenance of this package, if the package some day not updating their package when react native updating their library, ist gonna be worst scenario.

Related