简体   繁体   中英

Android WebView not caching HTTPS content

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.

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

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 (eg webviewCacheChromium/data_0 etc).

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.

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.

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

Thanks in advance,

Neil.

Sorted the problem.

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM