Android的WebView中不缓存HTTPS内容 [英] Android WebView not caching HTTPS content

查看:701
本文介绍了Android的WebView中不缓存HTTPS内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这显示在Android的WebView(的Andr​​oid Jelly Bean)的单页Web应用程序。这是一个体面的大小,所以我想利用缓存尽可能。

I have a single-page webapp which is displayed in an Android WebView (Android Jelly Bean). It's a decent size so I want to utilise caching as much as possible.

如果应用程序都通过HTTP,缓存填满约8兆和应用程序重新启动,网页内容从缓存加载几乎瞬间(没有网络流量观察)。

If the app is served over HTTP, the cache fills to about 8 meg and on an app re-start, the web content is loaded almost instantly from the cache (no network traffic is observed).

但是,如果应用程序是通过HTTPS提供,只缓存的一小部分被用于(几百K),并在应用程序重启,所有网络资产(JS / CSS等),从申请再次服务器。这是很难看到文件被缓存正是因为我没有一个根深蒂固的设备和文件看起来已经改名(例如webviewCacheChromium / data_0等)。

However, if the app is served over HTTPS, only a fraction of the cache is used (a few hundred K) and, on an app-restart, all the the web assets (JS / CSS etc) are requested from the server again. It's difficult to see exactly what files are being cached as I do not have a rooted device and the files look to have been renamed (e.g. webviewCacheChromium/data_0 etc).

我尝试设置的Cache-Control:max-age的'响应头(我相信这可以强制HTTPS在旧的浏览器缓存),但它并没有区别。

I tried setting the 'Cache-Control: max-age' response header (as I believe this can force https caching in older browsers) but it made no difference.

我找不到任何建议,一个web视图将不缓存默认使用HTTPS内容。我相信,大部分现代浏览器行为这种方式 - 我希望在Android的WebView做同样的。

I can't find anything to suggest that a WebView will not cache https content by default. I believe most modern browsers behave this way - I would expect the Android WebView to do the same.

我失去了一些东西在这里?做了的WebView需要被告知缓存HTTPS内容?

Am I missing something here? Does a WebView need to be told to cache https content?

由于提前,

尼尔。

推荐答案

排序的问题。

以防万一有人在同样的问题绊倒在未来....

Just in case anyone stumbles across the same problem in future....

原来的应用程序没有被正确缓存由于SSL错误(但遗憾的是正在应用其他吞噬)。基本上,如果你没有你的SSL证书正确设置,这是你会看到的。

It turns that the app was not being cached correctly due to an SSL error (which unfortunately was being swallowed elsewhere in the app). Basically, if you don't have your SSL certificates properly set-up, this is what you will see.

要检查该扩展 WebViewClient.onReceivedSslError()并记录任何错误。

To check this extend WebViewClient.onReceivedSslError() and log any errors.

我们有几个不同的错误,因为我们的SSL证书没有正确设置 - 。一旦这些是固定的,如预期的应用被缓存

We had a couple of different errors as our SSL certs weren't properly set-up - once these were fixed, the app was cached as expected.

希望这将节省别人的浪费时间,我经历了:)

Hopefully this will save someone the wasted hours that I went through :)

这篇关于Android的WebView中不缓存HTTPS内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆