Android的web视图的表现,我缺少什么?
希望有人能导致我在正确的方向在这里。我在一秒钟通过原生的Android浏览器加载查看时,手机网站,也许是两秒以内。当一个web视图内发生需要至少5秒钟,同一网站的加载,每次,不管是什么。浏览计算器寻求解决后,我说:
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. The same site when place within a webview takes at least 5 seconds to load, everytime, no matter what. After browsing stackoverflow seeking a solution, I have added:
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
和
//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);
}
不过,该网站加载pretty的慢。我知道本地比较快,但灵活性我掏的web视图。这里有什么想法?我失去了什么东西?
Still, the site loads pretty slow. I know native is faster, but for flexibility I dig the webview. Any ideas here? Am i missing something else?
嗯...花一些时间在这之后,我找到了罪魁祸首。加载JavaScript文件,并不重要,如果它是一个本地或远程文件,精缩等物质,增加了显著开销web视图的加载时间。此外,它并不重要,如果脚本放在或标签之前,结果是pretty的大致相同,至少在我的情况。
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. 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.
一个解决方案,我发现是使用 head.js 在一个非阻塞的方式加载脚本。它一定帮助。总之,只要张贴此为别人谁遇到了类似的情况。
One solution I found was to use head.js to load scripts in a non blocking manner. It definitely helped. Anyway, just posting this for others who run into a similar situation.