Ano-Tech Computers
Enter keyword:

AJAX: HTML reloads but images do not refresh
Problem:
When refreshing or updating part of a web page using AJAX (or similar techniques) some browsers will use cached images without checking for updates, even if the HTTP header indicates the image has expired.
 
Solution:
Add the current unixtime to the image file name like so:


The web server will interpret this as an encoded parameter and thrown it away when serving images. (If you are using parameters for your images, then I assume you know what you're doing. Maybe you're using an auto-thumbnailer or something)

Anyway, each HTML update will contain a slightly different image URL. defeating the (flawed) browser cache mechanism and cause the image to reload properly.

 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles