Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image Refresh

 
Lilian Chase
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm regenerating a new image using Ajax but using the same name for the image. However, due to the caching, the image shown is not changing.

I've used the method of appending a random query string and it works!

I'm using JQuery:


BUT, the problem is, it doesn't work all the time. Sometimes the image refreshes, sometimes no. Any idea what's the problem?

I've also tried adding meta tags to the JSP page, but still the same condition.



Any suggestions or help is greatly appreciated!
Thank you in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding meta tags to the parent page will have no affect on loaded images within the page.

Appending the random # is a common trick and it should work unless the "random" number just happens to repeat. You might try a counter instead.

If worse comes to worse, serve the image as a servlet where you can set the meta tags on the image response. Or change things around so that the same image name isn't always being re-used.
 
Lilian Chase
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still don't understand the unpredictable behaviour. I'd checked the queryString random number, it's different but the image still remains the same.

Anyway, I resorted to using randomly generated number as the filename. So problem solved (kind of).

But I still would like to know what causes the unpredictable refreshing behaviour. Maybe adding a setTimeout will help?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lilian Chase wrote:Maybe adding a setTimeout will help?

Random guessing is seldom fruitful.

I'd gather data regarding when it works and when it doesn't to see if a pattern emerged.
 
Lilian Chase
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Random guessing is seldom fruitful.


I'd been googling and found examples where they used a timer to refresh the duration. But you are right, I am just simply throwing ideas around.

Anyway, really thank you for your help so far
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic