[英]Android webview performance, what am I missing?
Hoping someone can lead me in the right direction here. 希望有人可以引导我朝正确的方向前进。 My mobile site when viewed through the native android browser loads in under a second, maybe two seconds max.
通过本机android浏览器查看时,我的移动网站的加载时间不到一秒钟,最多可能需要两秒钟。 The same site when place within a webview takes at least 5 seconds to load, everytime, no matter what.
无论何时何地,将同一站点放置在web视图中至少需要5秒钟的时间来加载。 After browsing stackoverflow seeking a solution, I have added:
浏览stackoverflow寻找解决方案后,我添加了:
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
and 和
//Disable Caching
try
{
Method m = CacheManager.class.getDeclaredMethod("setCacheDisabled", boolean.class);
m.setAccessible(true);
m.invoke(null, true);
}
catch (Throwable e)
{ Log.i("MyApp","Reflection failed", e);
}
Still, the site loads pretty slow. 不过,该网站的加载速度非常慢。 I know native is faster, but for flexibility I dig the webview.
我知道本机速度更快,但是出于灵活性考虑,我挖掘了Webview。 Any ideas here?
这里有什么想法吗? Am i missing something else?
我还有其他东西吗?
Well... after spending some time on this I found the culprit. 好吧……花了一些时间之后,我找到了罪魁祸首。 Loading Javascript files, doesn't matter if it's a local or remote file, minified, etc, adds significant overhead to the load time of the webview.
加载Javascript文件(无论是本地文件还是远程文件),压缩后的文件等等,都没有关系,这会大大增加WebView的加载时间。 Also, it does not matter if scripts are placed in the or before the tag, results are pretty much the same, at least in my case.
另外,脚本是否放置在标记中或标记之前也没关系,至少在我看来,结果几乎相同。
One solution I found was to use head.js to load scripts in a non blocking manner. 我发现的一种解决方案是使用head.js以非阻塞方式加载脚本。 It definitely helped.
它肯定有帮助。 Anyway, just posting this for others who run into a similar situation.
无论如何,只需将其发布给遇到类似情况的其他人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.