简体   繁体   中英

Storing Javascript locally in Android app, is this possible?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM