Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared cache between two WebViews

Is it possible to enable caching between multiple webviews? Here is the scenario:

  1. Activity A with WebView 1 is created to show xyz.com
  2. Later Activity B with WebView 2 is created to show xyz.com again

I tried webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); but the page (I use a large wikipedia page for testing) is still reloaded from the web instead of using the cache.

like image 590
Simon Avatar asked May 08 '26 20:05

Simon


1 Answers

According to the documentation, all WebViews in an application share their cache.

However, it looks like Wikipedia always sets the response headers in such a way as to mark the response un-cacheable:

Cache-Control:private, s-maxage=0, max-age=0, must-revalidate

So, I don't think that you're doing anything wrong, nor do I think that there is anything that you can to fix the situation with Wikipedia. Try a different web site, that uses a more 'normal' caching policy, and I'm sure that you will see the WebView's cache working as you expect.

like image 85
GreyBeardedGeek Avatar answered May 10 '26 11:05

GreyBeardedGeek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!