Browsing Jpg in Webview

exjey

Member
Licensed User
Longtime User
I am showing a jpg picture located on a server, using the webview object. This jpg may change from time to time and it has fixing name "mypic.jpg". In my company's site because the related page is a static one (html), everytime i change the picture i change also the name like "mypic23.jpg", "mypic24.jpg" because some browsers will not change the picture (using the cache) if the filename remains the same, even the content is changed (until you press "refresh-F5").

Do you think that my code (simple webview1.LoadURL("http://.../mypic.jpg")) will have problem and not reload the picture if the picture changes and the filename is fixed?Do i have to do some webview1 clear cache and how?
 

warwound

Expert
Licensed User
Longtime User
There is a simple workaround to prevent a WebView from caching a resource.
You add a bogus GET parameter to the URL:

B4X:
webview1.LoadURL("http://.../mypic.jpg?bogus_parameter="&DateTime.Now))

The WebView will not cache a resource which has a GET parameter in it's URL, each time the resource is used it will be requested afresh from the server.
Using DateTime.Now as the value of the bogus parameter ensures every request is unique.

You could instead clear the WebView cache before loading your image but that will be very inefficient - you'll end up reloading all web resources not just the image resource.

Martin.
 
Upvote 0
Top