0

I am rendering a webview on button click and am using the shouldInterceptRequest to intercept requests to resources like images, css and js files and serving them locally instead of over the network. I expected to see a considerable amount of difference in the load time but it reduced only by a small fraction. Is it possible to parallelize the shouldInterceptRequest ?Are there any other suggestions.

Thanks in advance

kshah
  • 31
  • 1
  • 3

1 Answers1

2

The new Chromium WebView present in KitKat will read multiple InputStreams returned from shouldInterceptRequest in parallel. The Classic WebView implementation present in previous versions of Android would perform the reads serially and there is no way around that.

Without knowing the details of the content you're trying to serve it's hard to offer specific suggestions. How are you measuring this? Maybe the total time to display went down, but you perceive the load as being slower because only one thing is loading at a time? You should also try experimenting with what to cache locally - maybe the biggest gain is from only having the biggest file be served via shouldInterceptRequest?

If you can afford the extra memory usage you could store your resources in memory (by reading them into a string, for example) and serve them to the WebView using a ByteArrayInputStream. It would be ideal if you could predict what the next required resource would be (that way you'd need less memory).

Note: the Classic WebView would use shouldInterceptRequest "under the hood" for reading file:///android_asset and content: scheme resources, so there is no benefit in transferring between any of those, however doing so (specifically using the file:///android_asset/) might simplify your code.

marcin.kosiba
  • 3,221
  • 14
  • 19
  • Thanks for the reply.. To answer your questions: I am currently setting timers to see how much time it is taking for rendering resources. Currently to get maximum performance I am caching all the resources locally in the securedStorageLocation on the device. How would one store the resources in memory. Could you point out the api I should use for this. These resources could be images or css files or js files. – kshah Nov 11 '13 at 19:47
  • Does storing resources in secureStorageLocation account as being in memory ? – kshah Nov 11 '13 at 19:56
  • @kshah - by in memory I mean in RAM. You could use code like [this](https://code.google.com/p/chromium/codesearch#chromium/src/android_webview/java/src/org/chromium/android_webview/AwResource.java&q=getRawFileResourceContent&sq=package:chromium&l=90&type=cs) to read a resource into RAM. – marcin.kosiba Nov 15 '13 at 00:23