Skip to content Skip to sidebar Skip to footer

How To Make Android Webview Clear Cache?

Here is my scenario. I am using WebView to show my mobile-ready website inside an app. We regularly update our website and automatically clear our website cache, so visitors get th

Solution 1:

Add a parameter to your js/css file link in the html code, that can be a datetime or version string, just like:

<linkrel='stylesheet'href='style/jquery.mobile-1.3.2.min.css?ver=1.3.2'><scriptsrc="js/jquery-1.8.3.min.js?ver=1.8.3"></script><scriptsrc="js/jquery.mobile-1.3.2.min.js?ver=1.3.2"></script><scriptsrc="js/my_script.js?ver=201603111428"></script>

When your script or style sheet file updtated, just change to a new parameter value, then the webview will treat it as a new url and make a reload.

Solution 2:

mWebView.getSettings().setAppCacheEnabled(false);
mWebView.clearCache(true);
mWebView.loadUrl("about:blank");
mWebView.reload();
mWebView.loadUrl("http:xxxxxxx");

I was looking for solutions too, but the only works for me was this commands.

Post a Comment for "How To Make Android Webview Clear Cache?"