React-native: [WebView] Caching contents WebView using the cachePolicy

Created on 19 May 2015  路  16Comments  路  Source: facebook/react-native

Currently the UIWebView is not caching the contents of webview. We need a provision to set cachePolicy if there is a boolean prop to set cache policy to the webview.

  NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:15.0];
  [_webView loadRequest:theRequest];
Locked

Most helpful comment

on man, why close this

All 16 comments

@arunshan - looks like a simple change, can you submit a PR?

I've submitted a pull request for this. @brentvatne, if you have any guidance on things that can/should be changed, please feel free to ping me.

What is the status of this? How can I enable this for my local project in the meantime?

@brentvatne Can @jaygarcia's solution be merged?

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/webview-caching-contents-webview-using-the-cachepolicy

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

oh,we need webview cathe ,it is very important for me!@mkonicek , please do not abandon this pr, it is very important

this is important, pls dont abandon this.

on man, why close this

Yes! We need this as well

any update.. waiting still in feb 18

Yeah, I need this too.

So, there are no any news?
Maybe someone knows how to save loaded HTML and paste it to Webview?

@ErickVoodoo If you are looking to do that as a workaround instead of having a WebView cache, you could grab the source and save it, then use a webview like <WebView source={{html:getYourContent()}} /> to load and display the required content. If you also had resources like images and css etc that you wanted to cache locally you'd have to reference them appropriately too - not sure of the details of that side of things, but maybe this would be a starting point.

Definitely not where we _want_ to head, but maybe a workaround that would be useful in the meantime.

@goldengecko Yesterday I did some work to solve my issue, I save HTML to my local storage, but: there is one issue, CSS and JS code which were pasted in tag were not loaded. So, I saved plain HTML without logic and styles, to be honest, this isn't what I want to get)

@goldengecko maybe you have some idea how to turn on cache on WebView? Now if there is no internet connection the WebView will fall down.

The main reason is to display the page when there is no internet connection. Maybe someone has some workarounds about that idea?

Please! We need this as well

This would be great. Also, the solution to just save the HTML resource to disk and load with <WebView source={{html: resource}} /> doesn't let you play with the URL parameters nicely.

Was this page helpful?
0 / 5 - 0 ratings