jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes Image Refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Image Refresh" Watch "Image Refresh" New topic
Author

Image Refresh

Lilian Chase
Greenhorn

Joined: Jun 14, 2010
Posts: 24
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lilian Chase
Greenhorn

Joined: Jun 14, 2010
Posts: 24
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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

Joined: Jun 14, 2010
Posts: 24
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
 
Don't get me started about those stupid light bulbs.
 
subject: Image Refresh
 
Similar Threads
using window.location ????
Browser Back Button
meta refresh tag is not working
redirect from servlet