网页流量性能流量、性能、网页

2023-09-07 02:47:14 作者:谁念西风独自凉

我渲染按钮点击网页视图和现在用的shouldInterceptRequest拦截请求如图像,CSS和JS文件的资源,并通过网络在当地为他们提供服务,而不是。我期望看到相当多负载的时间差,但它只有一小部分减少。是否可以并行化shouldInterceptRequest?是否有任何其他建议。

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.

在此先感谢

推荐答案

新铬的WebView present在奇巧将读取多个InputStreams从shouldInterceptRequest并行返回。 Android中的previous版本经典的WebView实现present将执行串行读操作并没有解决这个没办法。

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.

不知道内容的细节你想成为很难提出具体的建议。你是如何衡量的?也许,显示的总时间去了,但是你认为负载作为是慢,因为只有一件事是装在一个时间?你也应该尝试什么在本地缓存试验 - 也许是最大的收获是从只具有最大的文件通过shouldInterceptRequest送达

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?

如果你能负担得起额外的内存使用情况,你可以存储你的资源在内存中(通过读取它们放入一个字符串,例如),并使用一个ByteArrayInputStream为他们服务到的WebView。这将是理想的,如果你能predict一下下所需的资源将是(这样你需要更少的内存)。

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

注:经典的WebView将使用shouldInterceptRequest引擎盖下读文件:/// android_asset和内容:方案的资源,所以在任何这些之间传输没有任何好处,但是这样做(特别是使用文件:/// android_asset /)可能会简化您的code

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.

 
精彩推荐
图片推荐