react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[WebView] Caching contents WebView using the cachePolicy

Open arunshan opened this issue 11 years ago • 16 comments

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];

arunshan avatar May 19 '15 17:05 arunshan

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

brentvatne avatar May 29 '15 21:05 brentvatne

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.

jaygarcia avatar Sep 14 '15 17:09 jaygarcia

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

alexisvincent avatar Jan 09 '16 12:01 alexisvincent

@brentvatne Can @jaygarcia's solution be merged?

alexisvincent avatar Jan 09 '16 12:01 alexisvincent

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.

mkonicek avatar Apr 10 '16 17:04 mkonicek

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

aqnaruto avatar Jun 15 '17 06:06 aqnaruto

this is important, pls dont abandon this.

vvavepacket avatar Jul 05 '17 13:07 vvavepacket

on man, why close this

WangNingning1994 avatar Sep 13 '17 09:09 WangNingning1994

Yes! We need this as well

indrasantosa avatar Oct 19 '17 06:10 indrasantosa

any update.. waiting still in feb 18

sujitpk-perennial avatar Feb 14 '18 05:02 sujitpk-perennial

Yeah, I need this too.

goldengecko avatar Feb 19 '18 12:02 goldengecko

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

ErickVoodoo avatar Mar 14 '18 15:03 ErickVoodoo

@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 avatar Mar 14 '18 22:03 goldengecko

@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?

ErickVoodoo avatar Mar 15 '18 10:03 ErickVoodoo

Please! We need this as well

juanrodriguezarc avatar May 08 '18 21:05 juanrodriguezarc

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.

miraan avatar Jun 18 '18 07:06 miraan