7
votes

We have a Phonegap application that uses remotely served images.

The images are served with a Cache-Control header: 'Cache-Control': 'max-age=31536000'.

Prior to iOS 12, the images were fetched once and cached during the usage of the app. After upgrading to iOS 12, the cache stopped working and images are always fetched from the server. We use UIWebView (we have not yet migrated to WKWebView).

It does not happen in Safari on iOS 12 or any other platform (Android / web).

I cannot find any information on why this suddenly no longer works. Does anyone have a clue?

2
Unfortunately I cannot provide an actual answer, hence just this little comment: In a discussion on the apple dev forums (the link of which I lost long ago) I once read an apple engineer basically saying that we should not rely on deprecated things to stay unchanged. That's a bummer, I know, but taking a guess here I'd say that you're probably out of luck in solving this, or even getting an in-depth official explanation. It's likely that a side effect resulted in this behavior and Apple just decided "Meh, UIWebview's deprecated anyways". You'll probably have to migrate. Best of luck!Gero
I've worked a lot with WebView-based apps and I strongly recommend you to migrate yo WKWebView, since performance and other improvements are really worth it. In your case, I would suggest you to make a dummy app with a WKWebView that loads images with that cache, so you can test if migrating will solve your problem.CSolanaM
@CarlosSolanaMartínez Thank you for your feedback. Migrating to WKWebView does indeed fix the issue. However I am still scratching my head as to why Apple decided to change the way a deprecated class works (or it should be fallout from other changes).pj3s

2 Answers

0
votes

In the end we ended up migrating to WKWebView instead.

For Phonegap/Cordova users: I can highly recommend using cordova-plugin-ionic-webview: https://github.com/ionic-team/cordova-plugin-ionic-webview to quickly migrate to WKWebView instead of UIWebView.

0
votes

It seems UIWebView does NOT cache background-image. According to my test, using <img /> to load remote images, cache works as expected.

In addition, if we use a global variable to hold an Image of the same URL, UIWebView can cache background-image as well.

window.imageCache = new Image();
window.imageCache.src = 'https://xx.com/some/url/to/image';

// later in DOM, background images can be cached
// <div style="background: url(https://xx.com/some/url/to/image);"></div>