Martin
Martin

Reputation: 1822

force image reload html5

Is there a clean way to tell browser not to cache image in img tag like

<img src="" cahe="no-cache"/> 

or force reload it with html5? If not, maybe you know where can i suggest it, because the problem is around for quite a while...

I know you can attach "?randomstring" at the end of src parameter or use server scripting to read file and send it with headers, which is what i am doing now, so i'm not looking for a hack.

"no-cache", "expire" and other headers for whole document doesn't seem to work on image files or i am doing something wrong.

Upvotes: 2

Views: 1917

Answers (3)

Saeed Neamati
Saeed Neamati

Reputation: 35822

For each image, browser sends a separate request, web servers usually serve static files (including images, CSS stylesheets, JavaScript script files, etc.) directly without giving them to a kind of handler. Thus, you should consult your web server to set Cach-Contro headers as you said. Another way is to write an extension for your web server (ASP.NET has an integrated pipeline with IIS7 for example) to server static files yourself. That is the only way you can force cache-servers and clients not to cache your image and get it every time from server.

Upvotes: 0

Karoly Horvath
Karoly Horvath

Reputation: 96258

You have to set those headers for the images, check your web server's documentation to see how you can do that.

Upvotes: 0

Quentin
Quentin

Reputation: 943220

You have to set the caching headers for the image not the document.

HTML 5 adds nothing to control the caching of external resources.

Upvotes: 4

Related Questions