• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Image Refresh

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic