Eedresha
Eedresha

Reputation: 111

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?

Upvotes: 5

Views: 3987

Answers (1)

Eedresha
Eedresha

Reputation: 111

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.

Upvotes: 6

Related Questions