2

I am working on a heavily webview dependant application. Load times are decent now after optimizations on my web code, but its nowhere near speeds of a native app.

I wonder if its possible to store frequently used Javascript in the app itself, rather than loading it everytime from the server. Maybe a way to store/load that Javascript on the Webview.

Munir Basheer
  • 162
  • 11

2 Answers2

0

You can try changing WebSettings's setCacheMode Please refer to documentation given in this link.

Try changing it with LOAD_CACHE_ELSE_NETWORK.

Visit this link which might help you.

Community
  • 1
  • 1
RPB
  • 16,006
  • 16
  • 55
  • 79
  • I am already using `LOAD_CACHE_ELSE_NETWORK`. Is there a way to store the javascript codes itself on the app to be loaded for webview? – Munir Basheer Oct 04 '13 at 02:18
0

Just override the onPageFinished method from WebViewClient. This method is called when the page is finished loading, then you can inject JavaScript from your app via one of these two calls, depending on the version of Android.

For KITKAT and above use: webView.evaluateJavascript(jsString, null);

Where jsString is your string of JavaScript code.

For Android versions below KITKAT use: webView.loadUrl("javascript:" + jsString);

Again, where jsString is your string of JavaScript code.

rogerlsmith
  • 6,670
  • 2
  • 20
  • 25