简体   繁体   English

在Android Webview中预加载Javascript

[英]Preload Javascript in Android Webview

I am using a custom List View that contains some components like Image View, Text View and Web View. 我正在使用自定义列表视图,其中包含一些组件,例如图像视图,文本视图和Web视图。 I am using a List View because the data is not fixed and changes after every item click. 我使用的是列表视图,因为数据不是固定的,每次单击后都会更改。 So due to dynamic data I am using a list view, I am using BaseAdapter for this. 因此,由于动态数据,我正在使用列表视图,因此我正在使用BaseAdapter。

In WebView I am displaying some Math expressions. 在WebView中,我正在显示一些数学表达式。 For that I need local Javascript: all works fine but it takes around 4 to 5 seconds to load Javascript in WebView. 为此,我需要本地Javascript:一切正常,但在WebView中加载Javascript大约需要4到5秒钟。 After that, it starts rendering, so the total time to display output is 5 to 6 seconds. 之后,它将开始渲染,因此显示输出的总时间为5到6秒。

I want to reduce this time. 我想减少这个时间。 Is there any way that I can preload Javascript in WebView? 有什么办法可以在WebView中预加载Javascript?

The GetView() method every time creates a new instance of WebView and other components, so every time it's loading Javascript. 每次GetView()方法都会创建WebView和其他组件的新实例,因此每次加载Javascript时。

Is there any way in that I can use a preloaded Javascript Webview? 有什么办法可以使用预加载的Javascript Webview?

I think you should go through a library JAVA / Android to avoid the use of webview and thus improve performance. 我认为您应该浏览JAVA / Android库以避免使用webview从而提高性能。 Here is a topic that addresses the problem of mathematical expressions: MathML and Java 这是一个解决数学表达式问题的主题: MathML和Java

Dont have a solution for initial delay but subsequent delay to load the page when you scroll list view can be avoided by caching the html-page that is dynamically created by js. 没有初始延迟的解决方案,但是可以通过缓存由js动态创建的html-page来避免在滚动列表视图时加载页面的后续延迟。

You can associate each result (html result page) with an unique id (generated based on result to be rendered) and cache dynamically created html page in hashmap or lru cache (completely created page can be accessed after onPageFinished call back) against this id. 您可以将每个结果(html结果页)与唯一的ID(根据要呈现的结果生成)关联,并针对此ID在hashmap或lru缓存(可以在onPageFinished回调后访问完整创建的页面)中缓存动态创建的html页面。 When the list is scrolled up or down, instead of creating page dynamically by js again, you can fetch cached html page (now static page) that was created and just load the static page. 当列表向上或向下滚动时,您可以取回已创建的缓存html页面(现在为静态页面),而不必加载js再次动态创建页面,而只需加载静态页面即可。 This reduces the delay to load page as well as saves battery 这减少了加载页面的延迟并节省了电池

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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