Previously I wrote a post How to use OkHttp for loading resources in WebView.

Now, I definitely can say that it was bad idea. And it's not an OkHttp 's fault.

NotOk: loading WebView resources via OkHttp was bad idea (not OkHttp's fault). Flucking WebView :( — Artem Zinnatullin (@artem_zin) October 27, 2015

WebView problems

If you can avoid WebView — avoid it. WebView calls shouldInterceptRequest() synchronously in a single IO thread, so resources will be loaded synchronously one after another. Though, OkHttp is fast enough (SPDY, HTTP/2) that it may give better results on a good connection in compare to native loading of the resources via WebView . Looks like WebView blocks JavaScript execution until you load all resources in shouldInterceptRequest() . Also looks like native resources loading in the WebView somehow integrated into JavaScript execution queue so JS can do its work "in parallel" to native resources loading.

Unfortunately, most of integrated WebView s on Android < 5 and Android System WebView from Google Play affected with these problems.

But I still want to load resources myself!

If you still want to manually load resources of pages that you're displaying you can do it.

Suggested algorithm (suitable for email clients btw):

Load resources in background before WebView even displayed (for example if email app receives a new message in background, it can start pre-fetching images from the message even before user opens the app, of course with respect to connection quality and battery level). Override shouldInterceptRequest() and return result from pre-fetched cache if it exists, otherwise you can either return false and leave loading of the resource to the WebView or synchronously load it manually, but as mentioned before — WebView may stuck on a bad connection.

Another approach if you can't pre-fetch resources is to override shouldInterceptRequest() , immediately return some fake result and start async load of the requested resource, then when the resource will be downloaded you can trigger it's reload via JavaScript and return content from cache!

Bonus info