Hi all.
I have an app that receives a lot of images from a web server via web services calls. The images can change in the back-end, but Ionic’s default image caching system prevent the app from showing the latest modified images. I don’t want to apply some random date to the dynamic image’s URL as a solution because image caching is good for performance, so I want to know if it is possible to apply an expiry option for Ionic’s image caching?
Thanks.
Did you sort this one out? I have a very similar circumstance!
Nope! Ionic checks the URL of the image, if it changes, Ionic refresh the image, if the URL is the same, Ionic loads the cached image. My solution was to change the image URL in the back-end whenever a user changes it. That was the simplest solution I came up with.
Hope this helps.
Hmm! Yes I thought that was probably the case.
Are you aware of any method to disable the default ionic image caching altogether? Perhaps this would allow us to use something more flexible instead.
This was my question the first time, and as you can see, I didn’t get any answer which explains why I changed my code in the back-end instead of changing it in my mobile app’s code
Thanks. Yes I ended up solving my issue by adding a random element to the file names. Maybe this will help someone else?
In my controller I did:
$scope.randomImg = Math.random();
And in my template I did:
<img ng-src="http://domain.com/image.jpg?{{randomImg}}">
Now I have live image changes without having to change the names manually each time.
1 Like
I’ve done that before, that was stated in my question. But why this wasn’t a good idea for me, because my app shows a lot of images, and every image will be shown in different views, so applying a time stamp to force Ionic to re-render the image will increase the bandwidth usage in the backend, and make the app slow.
If your app is not “image intensive”, then maybe your solution is the best bet