Clear UIWebView cache on ios

I have a Phonegap application where I need to delete the html cache at some point because I updated the images in my application.

I tried this:

[[NSURLCache sharedURLCache] removeAllCachedResponses]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; [[NSURLCache sharedURLCache] setMemoryCapacity:0]; 

Called in the plugin via javascript, I do:

 location.reload( true ) 

But I still see the same image that seems to be caching.

Is there any other way to do this? I can tell the user to exit the application and kill it and restart it after.

Thanks!

+4
source share
4 answers

What you can try is to completely remove the cache directory in your application, for example, the first time you launch the application.

0
source

You may have a URL version control system for images. As I said here.

http://www.abksharma.in/2013/10/caching-using-javascript-versioning.html

request images with a parameter below the URL.

 http://s.wordpress.org/screenshots/3.5/ss5-dfw.gif?1 http://web-sniffer.net/ Above is truly cached image with below headers 

For DATA we can use below.

How to enable ajax request caching for semi-dynamic data (e.g. JSON)?

0
source

You can simply solve this by adding a timestamp after the URL. You can then verify that the URL you request each time is different.

Similarly: http://www.demo.com/xxxx?t= timestamp .

The javascript code is just like this:

 var url = 'xxxx/xxx?timestamp=' + Date.now(); 
0
source

None of them helped me.

I was afraid that I would have to resort to creating unique file names and cleaning up when this was done.

This worked perfectly.

 <img src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAeu ... snip data .... YII="> 

How to display Base64 images in HTML?

0
source

Source: https://habr.com/ru/post/1500760/


All Articles