Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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);

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. Any ideas here? Am i missing something else?

like image 339
Eedresha Avatar asked Feb 29 '12 17:02

Eedresha


1 Answers

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.

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.

like image 109
Eedresha Avatar answered Sep 27 '22 20:09

Eedresha