Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    Great! After a lot of time trying to load my web images which were being loaded with a delay I have just solved it by applying your solution (with '#', using '?' is not working for me). Many thanks!!! Commented Oct 24, 2013 at 7:57
  • 29
    There are TWO caches involved here: There's the browser's regular HTTP cache, and an in-memory cache of images it has displayed recently. This latter in-memory cache is indexed by the full src attribute, so adding a unique fragment identifier ensures that the image isn't simply pulled from memory. But fragment identifiers are not sent as part of HTTP requests, so the regular HTTP cache will be used as normal. That's why this technique works. Commented Mar 15, 2014 at 17:41
  • There is several header cache. actually I don't know english very well, can you please tell me should I use which one?! I want something that does not cache just the photo that is changed (like a captcha), and cache other things. so Cache-Control: max-age=0, must-revalidate is good for me? Commented Oct 3, 2015 at 17:01
  • 1
    It doesn't work for me. The only thing different in my case is that I have a url to a controller action which retrieves img from db. I had other arguments for the controller action so I added it as "......&convert=true&t=" + new Date().getTime(); and "......&convert=true#" + new Date().getTime();. Is there anything I am doing wrong? Commented May 6, 2016 at 16:31
  • 1
    To avoid the overhead of object creation and/or method call, you could use an incrementing integer as the cache-buster: newImage.src = "http://localhost/image.jpg#" + i++; Commented Jan 27, 2017 at 16:16