Android的web视图的表现,我缺少什么? [英] Android webview performance, what am I missing?

查看:143
本文介绍了Android的web视图的表现,我缺少什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人能导致我在正确的方向在这里。我在一秒钟通过原生的Andr​​oid浏览器加载查看时,手机网站,也许是两秒以内。当一个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.

这篇关于Android的web视图的表现,我缺少什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆